//+-----------------------global varribles------------------------------
var U = undefined;
var i = window.location.href.indexOf(".com");
var g_domainURL = window.location.href.substring(0, i + 4) + "webcollection/";
var B = {}; //B is the namespace of base classes.
if (typeof g === undefined) {
    var g = {};
}

g.config = {
    "backgoundColor": "#ffffff",
    "headBackgroundColor": '#629444'
};
g.DomainSuf = (function () {
    var exp = /(?:http:\/\/)?(?:(\w+)\.)?(?:(\w+)\.)(\w+)/g;
    var match = exp.exec(window.location.href);
    var i = window.location.href.indexOf(".com");
    if (match == undefined || match[1] == undefined) {
        var t = (/\/\/\w+/).exec(window.location.href)[0];
        return t.substring(2, t.length);
    } else {
        return match[1];
    }
})();
g.mainDomain = (function () {
    try {
        var t = (/(\w+\.){1}.[a-zA-Z0-9_-]+\//).exec(window.location.href)[0];
        return t.substring(0, t.length - 1);
    } catch (ex) {
        return '';
    }
})();
g.dragEle = U;
g.dragData = undefined;
g.files = [];
g.initialOffsetX = 0; //the offset between the lefttop of the ele and the position of the mouse
g.initialOffsetY = 0;
g.mainTableWidth = (function () { //适应屏幕
    if (Sys.isMiniScreen) {
        var a = Math.min(window.screen.width, window.screen.height),
            b = Math.min(window.availWidth, window.availHeight);
        if (a < 540) return window.screen.width - 80;
        if (Math.abs(a - 540) < Math.abs(b - 540)) {
            return window.screen.width * 0.8 - 50;
        } else {
            return window.screen.availWidth * 0.8 - 50;
        }
    } else {
        return window.screen.width * 0.4 + 300;
    }
})();
//alert(window.screen.width + "  " + window.screen.availWidth + " " + g.mainTableWidth);
g.volatileArray = [];
g.dataWebTable = [];
g.WebTable = [];
g.Category = [];
g.state = {};
g.subdir = "";
g.state.isOperable = false; //
g.state["search"] = false;
g.state.haveLogined = false; //在此次登录前是否已经登录。
g.state.isHostEUser = function () { //当前用户就是主人 E:equil
    if (g.user == U) return false;
    if (!g.user.username) return false;
    return (g.user.username.toLowerCase() == g.DomainSuf);
};
g.initialState = function () {
    if (g.subdir == "main") {
        if (g.state.isHostEUser()) {
            g.state.isOperable = true;
        }
    } else if (g.subdir == "private") {
        g.state.isOperable = true;
    } else {
        g.state.isOperable = false;
    }
};
g.returnFalse = function () {
    return false;
};


g.getPrivateData = function (paraStr) //获取私有数据
{

    g.subdir = "private";
    g.initialState();
    var t = $('privateID');
    if (t != undefined) {
        $('privateID').style.backgroundColor = "#54C11A";
    }
    $('hostID').style.backgroundColor = "";
    $('publicID').style.backgroundColor = "";
    var getDataURL = g.domainDirectory + "/SendDataToClient.aspx?owner=0&&flag=private&&paraStr=" + paraStr +"&&freshParam=" + (new Date).getTime();
    sendAndGetData(true, getDataURL, function (resTxt) {
        g.dataWebTable["main"] = eval('(' + resTxt + ')');
        g.page.bindData(g.dataWebTable["main"]);
        g.page.createDom();
        g.page.refresh();
    });
};

g.getMainData = function (paraStr) //获取用户主数据
{

    g.subdir = "main";
    g.initialState();
    var t = $('privateID');
    if (t != undefined) {
        $('privateID').style.backgroundColor = "";
    }
    $('hostID').style.backgroundColor = "#54C11A";
    $('publicID').style.backgroundColor = "";
    var getDataURL = g.URI.protocol + '://' + g.URI.authority + "/SendDataToClient.aspx?owner=0&&flag=main&&paraStr=" + paraStr +"&&freshParam=" + (new Date).getTime();
    sendAndGetData(true, getDataURL, function (resTxt) {
        g.dataWebTable["main"] = eval('(' + resTxt + ')');
        g.page.bindData(g.dataWebTable["main"]);
        g.page.createDom();
        g.page.refresh();
    });
};

g.getPublicData = function (paraStr) //获取公共数据
{
    g.subdir = "public";
    g.initialState();
    var t = $('privateID');
    if (t != undefined) {
        t.style.backgroundColor = "";
        //_.setUserInfo();
    }
    $('hostID').style.backgroundColor = "";
    $('publicID').style.backgroundColor = "#54C11A";
    var getDataURL = g.domainDirectory + "/SendDataToClient.aspx?owner=0&&flag=public&&paraStr=" + paraStr+"&&freshParam=" + (new Date).getTime();
    sendAndGetData(true, getDataURL, function (resTxt) {
        g.dataWebTable["main"] = eval('(' + resTxt + ')');
        g.page.bindData(g.dataWebTable["main"]);
        g.page.createDom();
        g.page.refresh();
    });

};

if (g.user == undefined) {
    g.user = new User(lib.cookie.get("username"));
}

g.disLoginAndRegister = function () { //显示'登录与注册'界面，并获取相关类。
    g.lightOn = new LightOn($('light'));
    return g.LightOn;
};

g.tip = (function () {
    var unique;

    function constructor() {
        var ele = $CE("DIV");
        $SA(ele, "style", "left: 50%;transform: translateX(-50%);position: fixed;text-align:center;background-color:yellow;top:0px;padding: 0 20px;z-index:9;opacity:.70;moz-opacity:0.7;filter:alpha(opacity=40);");
        document.body.appendChild(ele);
        return ele;
    }
    return {
        getInstance: function () {
            if (!unique) {
                unique = constructor();
            }
            return unique;
        },
        display: function () { //(msg,q) q表示时间延迟.
            var t = this.getInstance();
            //t.style.top = (document.body.scrollTop || document.documentElement.scrollTop) + "px";
            jQuery(t).append(arguments[0] + "<div style='font-size: 14px;'>✔</div>");
            var sec = 5000;
            if (arguments.length > 1) {
                sec = arguments[1] * 1000;
            }
            setTimeout(function () {
                if (U != t.parentNode) t.parentNode.removeChild(t);
                unique = U;
            }, sec);
        },
        clear: function () {
            if (unique != U) unique.parentNode.removeChild(unique);
        }
    }
})();

function stopEvent(e) {
    if (!e) e = window.event;
    if (e.stopPropagation) {
        e.stopPropagation();
    } else {
        e.cancelBubble = true;
    }
    if (e.preventDefault) {
        e.preventDefault();
    } else {
        e.returnValue = false;
    }
}

function voidFun() {
    if (!e) e = lib.getEvent();
    e = EventUtil.formatEvent(e);
    if (e.stopPropagation) e.stopPropagation();
    else e.cancelBubble = true;
    return false;
}
window.onresize = function () {
    g.page.refresh(); //当窗口改变时，重新布局.
};

if (!Array.prototype.forEach) {
    Array.prototype.forEach = function (fun /*, thisp*/ ) {
        var len = this.length;
        if (typeof fun != "function")
            throw new TypeError();

        var thisp = arguments[1];
        for (var i = 0; i < len; i++) {
            if (i in this)
                fun.call(thisp, this[i], i, this);
        }
    };
}

/** 公共代码 ***/
// IE浏览器的Array对象缺少indexOf方法，加到原型对象上
if (!Array.indexOf) {
    Array.prototype.indexOf = function (obj) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == obj) {
                return i;
            }
        }
        return -1;
    }
}
// 绑定事件响应
Object.prototype.on = function (type, callback) {
    if (this.attachEvent) {
        this.attachEvent("on" + type, callback);
    } else if (this.addEventListener) {
        this.addEventListener(type, callback, false);
    }
}
// 解除事件响应
Object.prototype.off = function (type, callback) {
    if (this.attachEvent) {
        this.detachEvent("on" + type, callback);
    } else if (this.addEventListener) {
        this.removeEventListener(type, callback, false);
    }
}
//解决IE的Object.prototype的BUG
if (!document.on) {
    document.on = Object.prototype.on;
    document.off = Object.prototype.off;
}
// 简化对象获取方法
function $(obj) {
    if (typeof obj == "string") {
        obj = document.getElementById(obj);
    }
    //解决IE的Object.prototype的BUG
    if (obj && !obj.on) {
        obj.on = Object.prototype.on;
        obj.off = Object.prototype.off;
    }
    return obj;
}

function u(p) {
    return (p == U) ? true : false;
}

function funForWebEleDblclick() //准备编辑web元素.
{
    var t = new EditWeb(getDataByMouse(g.mouseEvent).webData);
}

function oneLayerClone(source) {
    var tmp = {};
    for (var i in source) {
        tmp[i] = source[i];
    }
    return tmp;
}

function arrayContainer(p) { //a class
    var _ = this;
    _.arr = [];
    _.length = p;
    _.push = function (value) {
        _.arr.push(value);
        if (_.arr.length > _.length) {
            _.arr.splice(0, 1);
        }
    };

    _.clear = function () {
        _.arr.length = 0;
    };
}
//+--------------------event handler------------------------------------
var eventHandler = {
    eventType: -1,
    isMove: false,

    g_eventArray: new arrayContainer(10),

    paramForMousedown: U,
    paramForMouseup: U,
    paramForClick: U,
    paramForDblclick: U,

    funForMousedown: U,
    funForMouseup: U,
    funForClick: U,
    funForDblclick: U,

    invokeFun: function () {
        eventHandler.getEvent();

        switch (eventHandler.eventType) {
            case 0: //down  
                if (!u(eventHandler.funForMousedown)) {
                    eventHandler.funForMousedown();
                }
                break;

            case 1: //up           
                if (eventHandler.funForMouseup) {
                    eventHandler.funForMouseup();
                    eventHandler.funForMouseup = null;
                }
                break;

            case 2: //click
                if (eventHandler.funForClick) //eventHandler.funForClick isn't null
                {
                    eventHandler.funForClick();
                    eventHandler.funForClick = null;
                }
                break;

            case 3: //dblclick
                if (eventHandler.funForDblclick) {
                    eventHandler.funForDblclick();
                    eventHandler.funForDblclick = null;
                }
                break;

            case 4: //
                break;
        }
    },

    fun_onmousemove: function () {
        g.mouseEvent = oneLayerClone(lib.formatEvent(arguments[0]));
        if (!u(g.WebActive) && g.WebActive.isLMousedown == 1) {
            eventHandler.g_eventArray.push(g.mouseEvent);
            setTimeout(eventHandler.setMoveToTrue, 1000);
            eventHandler.eventType = 4;
        }
    },

    setMoveToTrue: function () {
        g.WebActive.isLMousedown = 0; //tag the left mouse to "up" after 1000 milliseconds.
    },

    fun_onmousedown: function (evt) {
        g.mouseEvent = lib.formatEvent(evt);
        var trigger = g.mouseEvent.target;

        switch (trigger.getAttribute("eleFlag")) {
            case "webEle":
                break;
            default:
                break;
        }
        if (trigger.tagName == "TD") { //if the trigger is row element.
            specialEffect.m(trigger.parentNode, lib.formatEvent(evt));
            return;
        } else {

        }
        eventHandler.g_eventArray.push(g.mouseEvent);

        setTimeout(eventHandler.invokeFun, 400);

        stopEvent(g.mouseEvent);
    },

    fun_onmouseup: function () {
        g.mouseEvent = oneLayerClone(lib.formatEvent(arguments[0]));
        eventHandler.g_eventArray.push(g.mouseEvent);
    },

    fun_onclick: function () {
        var trigger = lib.formatEvent(arguments[0]).target;

        switch (trigger.getAttribute("eleFlag")) {
            case "webEle": //the object is a "web"
                eventHandler.funForClick = funForWebEleClick;
                break;

            case "CateNameEle": //the object is a category name
                eventHandler.funForClick = funForCateEleClick;
                break;

            default:
                break;
        }

        g.mouseEvent = oneLayerClone(lib.formatEvent(arguments[0]));
        eventHandler.g_eventArray.push(g.mouseEvent);
    },


    fun_ondblclick: function () {
        switch (lib.formatEvent(arguments[0]).target.eleFlag) {
            case "CateNameEle":
                eventHandler.funForDblclick = funForCateEleDblclick;
                break;

            default:
                break;
        }
        g.mouseEvent = oneLayerClone(lib.formatEvent(arguments[0]));
        eventHandler.g_eventArray.push(g.mouseEvent);
    },

    reseteventType: function () {
        eventHandler.eventType = -1;
        eventHandler.g_eventArray.clear();
    },

    getEvent: function () { //determine the event of "dblclick" "click" "mousedown" "mouseup" "mousemove".
        if (eventHandler.isMove == true) {
            eventHandler.isMove = false;
            eventHandler.eventType = -1;
            return;
        }

        if (eventHandler.g_eventArray.arr.length < 1) return;
        var firstTime = eventHandler.g_eventArray.arr[0].time;


        for (var i = 0; i < eventHandler.g_eventArray.arr.length && eventHandler.g_eventArray.arr[i].time > firstTime - 800; i++) {
            if (eventHandler.g_eventArray.arr[i].type == "dblclick") {
                eventHandler.eventType = 3;
                eventHandler.g_eventArray.clear();
                return;
            }
        }

        for (var i = 0; i < eventHandler.g_eventArray.arr.length && eventHandler.g_eventArray.arr[i].time > firstTime - 800; i++) {
            if (eventHandler.g_eventArray.arr[i].type == "click") {
                eventHandler.eventType = 2;
                eventHandler.g_eventArray.clear();
                return;
            }
        }

        for (var i = 0; i < eventHandler.g_eventArray.arr.length && eventHandler.g_eventArray.arr[i].time > firstTime - 800; i++) {
            if (eventHandler.g_eventArray.arr[i].type == "mousemove") {
                eventHandler.eventType = 4;
                eventHandler.g_eventArray.clear();
                return;
            }
        }

        if (eventHandler.g_eventArray.arr[0].type == "mouseup") {
            eventHandler.eventType = 1;
        }

        if (eventHandler.g_eventArray.arr[0].type == "mousedown") {
            eventHandler.eventType = 0;
        }

        eventHandler.g_eventArray.clear();
    },

    displayEventType: function () {
        eventHandler.getEvent();
        document.getElementById("result").innerHTML += "<br/>Event Type:" + eventHandler.eventType;
    }
}


//+----------------------specialEffect---------------------------------
var SpecialEffect = function () {
    var _ = this;
    _.placeElement = function (fromElement, preFromElement, elementContainer, eventType) {
        if (eventType == event.type) {
            g.elementDragClass.drag.ele.removeNode(true);

            if (elementContainer.clientLeft < event.x && event.x < elementContainer.clientLeft + elementContainer.clientWidth && elementContainer.clientTop < event.y && event.y < elementContainer.clientTop + elementContainer.clientHeight) {
                elementContainer.appendChild(g.elementDragClass.saved.ele);
                close(g.elementDragClass.source.ele);
            } else {
                g.elementDragClass.source.ele.style.cssText = g.elementDragClass.saved.ele.style.cssText;
            }
        }

    };


    _.m = function (p, e) { //drag the row of a category and webs.
        if (e.target.tagName != "TD") return;
        g.elementDragClass = new ThreeDomEleClass(p, p.cloneNode(true), p.cloneNode(true));
        if (u(g.elementDragClass) || u(g.elementDragClass.drag.ele)) return;
        g.tableRowWeb = getDataByMouse(e);
        if (u(g.tableRowWeb.rowData)) {
            return;
        }

        var dragTableDiv = $CE("DIV"); //create a DIV element to contain the table. It can be dragged.
        var dragTable = g.tableRowWeb.tableData.E.cloneNode(false);

        dragTable.appendChild(g.elementDragClass.drag.ele);
        lib.dom.clearChildren(dragTableDiv);
        dragTableDiv.appendChild(dragTable);
        dragTableDiv.innerHTML = dragTableDiv.innerHTML;
        dragTableDiv.firstChild.className = "noRound";
        dragTableDiv.style.display = "inline";
        dragTableDiv.style.position = "absolute";
        dragTableDiv.style.cursor = "move";
        dragTableDiv.style.width = g.tableRowWeb.rowData.RecRight - g.tableRowWeb.rowData.RecLeft + 'px';

        var startX = findPos(p).absoluteLeft;
        var startY = e.clientY;
        var origY = g.elementDragClass.source.ele.offsetTop;
        var deltaY = startY - origY;
        //alert("006;");
        iDiffX = e.clientX - g.tableRowWeb.rowData.RecLeft;
        iDiffY = e.clientY - g.tableRowWeb.rowData.RecTop;

        // g.elementDragClass.source.ele.style.visibility = "hidden";
        if (dragTableDiv.style.left == "") {
            dragTableDiv.style.left = e.clientX - iDiffX + "px";
            dragTableDiv.style.top = e.clientY - iDiffY + "px";
        }

        g.elementDragClass.drag.ele = document.body.appendChild(dragTableDiv);

        if (document.addEventListener) {
            document.onmousemove = moveHandler;
            document.onmouseup = upHandler;
        } else if (document.attachEvent) {
            dragTableDiv.setCapture();
            dragTableDiv.onmousemove = moveHandler;
            dragTableDiv.onmouseup = upHandler;
            dragTableDiv.onlosecapture = upHandler;
        } else {
            var oldmovehandler = document.onmousemove;
            var olduphandler = document.onmouseup;
            document.onmousemove = moveHandler;
            document.onmouseup = upHandler;
        }

        function moveHandler(e) { //moving
            if (!e) {
                e = lib.getEvent();
            }
            e = EventUtil.formatEvent(e);
            dragTableDiv.style.left = e.clientX - iDiffX + "px";
            dragTableDiv.style.top = e.clientY - iDiffY + "px";


            if (e.stopPropagation) e.stopPropagation();
            else e.cancelBubble = true;
        }

        function upHandler(e) //edit        after moving
        {
            if (!e) e = lib.getEvent();
            var tmpIDs = g.elementDragClass.source.ele.getAttribute("relationalID").split("-");
            var tmpWebRow = g.page.$(tmpIDs[0]).$(tmpIDs[1]);
            tmpWebRow.dragEle = dragTableDiv;
            tmpWebRow.funForLMouseUpAfterMoveWhileDown();
            if (document.removEventListener) {
                document.onmouseup = null;
                document.onmousemove = null;
                document.removeEventListener("mouseup", upHandler, true);
                document.removeEventListener("mousemove", moveHandler, true);
            } else if (document.detachEvent) {
                dragTableDiv.onlosecapture = null;
                dragTableDiv.onmouseup = null;
                dragTableDiv.onmousemove = null;
                dragTableDiv.releaseCapture();
            } else {
                document.onmouseup = olduphandler;
                document.onmousemove = oldmovehandler;
            }

            if (e.stopPropagation) e.stopPropagation();
            else e.cancelBubble = true;
        }
    };
}
//++---------------------------------------------------------------
var specialEffect = new SpecialEffect();
//+-----------------------------------------
function ThreeDomEleClass(a, b, c) // the data structure of the web to be dragged.
{
    var _ = this;
    _.source = {
        ele: a,
        parent: _
    };
    _.saved = {
        ele: b,
        parent: _
    };
    _.drag = {
        ele: c,
        parent: _
    };
    _.empty = function () {
        if (U != _.source.ele) _.source.ele.outerHTML = "";
        if (U != _.saved.ele) _.saved.ele.outerHTML = "";
        if (U != _.drag.ele) _.drag.ele.outerHTML = "";
    }
}
// base class
function Region() {
    var _ = this;
    _.RecLeft = 0;
    _.RecTop = 0;
    _.RecRight = 0;
    _.RecBottom = 0;

    //set the rectangle of every web element.
    _.setRec = function (p, q, right, bottom) {
        _.RecLeft = p;
        _.RecTop = q;
        _.RecRight = right;
        _.RecBottom = bottom;
    };

    _.setRecByEle = function () {
        _.RecLeft = 0;
        _.RecTop = 0;
        _.RecRight = 0;
        _.RecBottom = 0;

        var t = _.E;
        if (t.offsetParent) {
            while (1) {
                _.RecLeft += t.offsetLeft;
                _.RecTop += t.offsetTop;
                if (!t.offsetParent) {
                    break;
                } else if (t.offsetParent.style.position == "absolute") {
                    _.RecLeft += t.offsetParent.offsetLeft;
                    _.RecTop += t.offsetParent.offsetTop;
                    break;
                }
                t = t.offsetParent;
            }
        } else if (t.x && t.y) {
            _.RecLeft += t.x;
            _.RecTop += t.y;
        }
        _.RecRight = _.RecLeft + _.E.offsetWidth;
        _.RecBottom = _.RecTop + _.E.offsetHeight;

        return _;
    };

    _.refresh = function () {
        _.setRecByEle();

        var childEles = _.Webs || _.Categories || _.Tables;

        if (u(childEles)) {
            return _;
        }
        for (var i = 0; i < childEles.length; i++) {
            childEles[i].refresh();
        }
        return _;
    };

    //judge
    _.isOver = function (x, y) {
        try {
            return (x > _.RecLeft && x < _.RecRight && y > _.RecTop && y < _.RecBottom) ? true : false;
        } catch (e) {
            return false;
        }
    };

    _.isOverEvent = function (p) {
        var t = lib.formatEvent(p);
        return _.isOver(t.pageX, t.pageY);
    };
}

//message data structure
function message(from, to, owner, content, webTable) {
    this.from = from;
    this.to = to;
    this.owner = owner;
    this.content = content;
    this.webTable = webTable;
    this.isRead = 0; //0 stands for being  unread; 1 stands for being unread.
}

//user data structure
function User(p, q, image) {
    var _ = this;
    _.username = (!!p) ? p.toLowerCase() : p;
    _.email = q;
    _.image = image;
    _.messages = [];
    _.friend = [];
    /*
    example: if(false == g.user.isLogined()){
        var tmp = g.disLoginAndRegister();
        //do something else.
    }
    */
    _.isLogined = function () { //判断是否已经登录：是则返回true。
        if (_.username == U) {
            return false;
        } else {
            return true;
        }
    };
    _.logOut = function () {
        lib.cookie.clear("username", "/");
        _.username = U;
        _.setUserInfo();
        g.getMainData(); //禁止查看私人数据，因此显示主人数据。
    };

    _.logIn = function () {

    };

    _.sendMessage = function () {};

    _.getMessage = function () {

    };

    _.setUserInfo = function () {
        if (U != _.username) {
            lib.cookie.set("username", _.username, 30, "/", true);
            if (g.state.haveLogined == false) {
                g.tool.menu.insertItem(1, "<a id='userID' href='javascript:g.goUserPage();'>" + _.username + "</a>");
                g.tool.menu.insertItem(2, "<a href='javascript:g.user.logOut();'>" + lan["loginOut"] + "</a>");
                +               g.tool.menu.insertItem(3, "<a id='privateID' href='#" + paraStr+"/private'>" + lan["21"] + "</a>");
                                                                                             } else { //if(g.state.haveLogined == true) 如果已经有用户登录，则更新当前用户名。
                g.tool.menu.updateItem(1, "<a id='userID' href='javascript:g.goUserPage();'>" + _.username + "</a>");
            }
            g.state.haveLogined = true;
        } else {
            if ($("userID") != U) { //如果不加这个判断会删除其它菜单项。
                g.tool.menu.removeItemByIndex(1);
                g.tool.menu.removeItemByIndex(1);
                g.tool.menu.removeItemByIndex(1);
            }
            g.state.haveLogined = false;
        }
    }
}

function Friend(p_ele) {
    var _ = this;
    _.ele = p_ele;
    _.users = [];

    _.AddUser = function (p_user) {
        _.users.push(p_user);
    };

    _.DelUser = function (p_user) {
        for (var i = 0; i < _.users.length; i++) {
            if (p_user === _.users[i]) {
                _.users.splice(i, 1);
                return;
            }
        }
    };

    _.DisUser = function () { //显示好友用户。
        var tmp = [];
        for (var i = 0; i < _.users.length; i++) {
            tmp.push(_.users[i].username);
        }
        document.body.appendChild(lib.dom.createTable(tmp, "friendID"));
    };
}

//绑定document.body的onmousemove事件。
function MoveEle(e) {

}


document.body.onmousemove = function () {
    if (g.dragData == undefined) {
        var e = lib.formatEvent();
        var target = e.target;
        var tripData = getDataByMouse(e);
        if (!tripData) {
            return;
        }
        var currentData = tripData.webData || tripData.rowData || tripData.tableData;

        if (currentData != undefined) {
            if (currentData.isLDown == false)
                return;
            //计算拖动距离。
            var distance = Math.sqrt(Math.pow((e.x - currentData.firLDownClientX), 2) + Math.pow((e.y - currentData.firLDownClientY), 2));
            //如果鼠标左键是按下状态，且拖动较大距离，则表明是拖动事件。
            if (distance > 5) {
                console.log(g.dragData);
                if (g.dragData == undefined) { //start dragging.
                    currentData.funForStartLMouseMoveWhileDown();
                }
            }
        }
    } else {
        g.dragData.funForLMouseMoveWhileDown();
    }
};



function EventForEle(p) {
    var _ = this;
    _.EleToEvent = p.E;
    _.isLDown = false; //鼠标左键是否被按下
    _.isRDown = false; //鼠标右键是否被按下
    _.isLMoveWhileDown = false; //鼠标左键是否在被按住拖动.
    _.firRDownT = null; //鼠标右键被按下的时间
    _.firRUpT = null; //鼠标右键被放起的时间
    _.isDbClick = 0; //鼠标左键是否被双击.
    _.firClickTime = null; //第一次单击的时间
    _.secClickTime = null; //第二次单击的时间，可以根据时间差_.secClickTime-_.firClickTime判断鼠标事件是"一般单击"还是"双击"
    //鼠标位置相对所在元素顶点的
    _.firLDownClientX = 0; //鼠标左键第一次被按下所在的位置
    _.firLDownClientY = 0;

    _.firLDownT = null;
    _.firUpT = null;

    _.timeFunName = null;

    _.active_element;
    _.bIsMSIE;

    _.isLButton = function (e) {
        if (navigator.userAgent.indexOf("MSIE") > 0)
            return lib.getEvent().button == 1; //IE中左键标记为1
        else
            return lib.getEvent().button == 0; //Firefox中左键标记为0
    };

    _.isRButton = function () {
        if (navigator.userAgent.indexOf("MSIE")) //is IE
            return lib.getEvent().button == 2;
        else
            return lib.getEvent().button == 2;
    };

    //任务1,当鼠标移至此元素区域内时，此事件发生；
    _.EleToEvent.onmouseover = function () {
        return false;
    };

    //任务2,当鼠标离开此元素区域内时，此事件发生；
    _.EleToEvent.onmouseout = function () {
        return false;
    };

    //任务3,在此元素区域中，当鼠标左键按住不放时，调用functioin  funcAMouseOn(){//do something}。
    _.funcAMouseOn = function () {

    };

    _.EleToEvent.onmousedown = function () {
        var e = lib.getEvent();
        if (_.isLButton(e)) {
            _.firLDownT = new Date();
            _.isLDown = true;
            _.firLDownClientX = e.clientX; //记录第一次按下鼠标的位置，用于判断是否为移动事件，当幅度>5px判定为移动.
            _.firLDownClientY = e.clientY;
            _.funcAMouseOn(e);
        } else if (_.isRButton(lib.getEvent())) {
            _.isRDown = true;
            _.firRDownT = new Date();
        }
        return false; //阻止消息向外层元素传播.
    };

    //任务5,在此元素区域中，当鼠标左键按住一段时间后放开时，调用functioin  funcBLeftMouseUp(){//do something}。
    _.funcBLeftMouseUp = function () {
        //"调用funcBLeftMouseUp";
        if (_.isLMoveWhileDown == true) { //如果按住移动元素后放开
            _.isLMoveWhileDown = false;
            p.funForLMouseUpAfterMoveWhileDown();
        } else { //如果按住元素静止一段时间后放开
            p.funForLMouseUp();
        }
        _.isFirstMousedownMove = false; //恢复到初始标识状态。
    };

    _.funcBRightClick = function () {
        //调用funForRMouseClick
        p.funForRMouseClick(); //鼠标右键单击.
    };

    //_.a.onmouseup=function(){if(_.isLDown)_.funcBLeftMouseUp();_.isLDown=false;} ;
    _.EleToEvent.onmouseup = function () {
        if (_.isLButton(lib.getEvent())) {
            _.firUpT = new Date(); //记录左键第一次放开的时间.
            if (_.isLDown) _.funcBLeftMouseUp();
            _.isLDown = false;
        } else if (_.isRButton(lib.getEvent())) {
            _.firRUpT = new Date();
            if (_.isRDown && (_.firRUpT.getTime() - _.firRDownT.getTime() < 200)) {
                _.funcBRightClick();
                _.isRDown = false;
            }
        }
        return false; //阻止消息向外层元素传播.
    };

    if (window.attachEvent) {
        _.active_element = document.activeElement;
        _.bIsMSIE = true;
        document.onfocusout = function () {
            if (_.bIsMSIE && (_.active_element != document.activeElement)) {
                _.active_element = document.activeElement;
            } else {
                if (_.isLDown) _.funcBLeftMouseUp();
                _.isLDown = false;
            }
        };
    } else {
        window.onblur = function () {
            if (_.isLDown) _.funcBLeftMouseUp();
            _.isLDown = false;
            return false; //阻止消息向外层元素传播.
        };
    }

    //任务6,在此元素区域中，当单击鼠标左键时，调用functioin  funcBLeftClick(){//do something}。
    // _.funcBLeftClick = function () {
    //     //调用funcBLeftClick";
    //     p.funForLMouseClick();
    // };

    _.EleToEvent.onclick = function () {
        clearTimeout(_.timeFunName);
        _.timeFunName = setTimeout(function () {
            if (_.isDbClick == 0 && _.firUpT && _.firUpT && _.firUpT.getTime() - _.firLDownT.getTime() < 500) { //如果不是双击事件时，且按下左键与放开左键的时间间隔小于500ms，则认定为单击事件.
                // _.funcBLeftClick();
            }
            _.isDbClick = 0;
        }, 300); //在单击事件完成300ms后，判断此事件是单击还是双击.
        return false; //阻止消息向外层元素传播.
    };

    _.funcBLeftDbClick = function () {
        //"调用funForLMouseDblclick";
        if (p.funForLMouseDblclick)
            p.funForLMouseDblclick();
    };


    _.EleToEvent.ondblclick = function () {
        _.isDbClick = 1;
        _.funcBLeftDbClick();
        return false; //阻止消息向外层元素传播.
    };
}
//-----------------------------------------------------------

//+-------------------------class web------------------------
B.Web = function (p, q, Link, Note, Cate, Cr, Key, Lans, tagName, parent) //Flag 1
{
    Region.call(this); //inherit from the Class Region
    if (B.WebBase != U) {
        B.WebBase.call(this);
    }
    var _ = this;
    _.ID = p.toString();
    _.Name = q;
    _.Link = Link || "";
    _.Note = Note || '';
    _.Cate = Cate; //category.
    _.Cr = Cr; //creator
    _.Key = Key;
    _.Lans = Lans; //languages
    _.E = document.createDocumentFragment();
    _.EditEle = U; // the element of editting the "web" data.
    _.ShowDeleteEle = $CE("DIV");
    _.isSelected = false;
    _.isLMousedown = 0; //while the left mouse is pressed down and haven't been released.

    _.ContainerFlag = 0;
    _.Parent = parent;

    _.isFirstMousedownMove = false;
    _.initialOffsetX = 0; //the offset between the lefttop of the ele and the position of the mouse
    _.initialOffsetY = 0;
    _.c = function () {
        if (!!_.Link) { //_.Link is not null.
            _.E = $CE("SPAN");
            if (_.Link.match(/(http|https|ftp|mms|rtsp|gopher|socks4|socks5|thunder|flashget|qqdl):\/\/.*/)) {
                // _.E.href = _.Link;
                _.E.href = 'javascript:;'
            } else if (_.Link.match(/[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-]*[\w@?^=%&amp;\/~+#-])?/)) {
                _.E.href = 'javascript:;'
            } else {
                _.E.href = 'javascript:;'
            }
        } else {
            _.E = $CE("SPAN");
        }
        $SA(_.E, "id", "webElement2010" + _.ID);
        $SA(_.E, "Link", _.Link);
        $SA(_.E, "Note", _.Note);
        $SA(_.E, "Cate", _.Cate);
        $SA(_.E, "eleFlag", "webEle");
        _.E.onselectstart = function () {
            return false;
        };
        _.E.title = _.Note;
        jQuery(_.E).addClass('web_page_table_row_a_middle');
        _.E.innerHTML = _.Name;
        var timerId = ''
        _.E.addEventListener("click", function () {
            console.log(timerId)
            if (timerId) {
                console.log(2222)
                clearTimeout(timerId)
                timerId = ''
                new EditWeb(_);
            } else {
               console.log(11111)
                timerId = setTimeout(function() {
                    timerId = ''
                    if (/iPad|iPhone|iPod/.test(navigator.userAgent) && /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent)) {
                        location.href = /^((?!http).)+\..+/.test(_.Link) ?  winOpen.location = 'http://' + _.Link : _.Link;;
                        return;
                    }
                    if(/^((?!http).)+\..+/.test(_.Link)) {
                        window.open('http://' + _.Link, '_blank').location;
                        
                    } else {
                        window.open(_.Link, '_blank').location;
                    }

                }, 1000);
            }

        })
        // _.E.addEventListener("dbclick", function () {
        //     console.log(2211)
        // })
        _.funForLMouseDown = function () {};
        _.funForLMouseUp = function () {};
        // _.funForLMouseClick = function () {
        //     console.log(1)
        //     if (Sys.isMiniScreen) {
        //         // 显示下垂式编辑框
        //         var webDialogTag = document.createElement('div');
        //         webDialog.innerHTML = "<a href='" + this.Link + "'>open</a><br/>";
        //         webDialog.innerHTML += "title: <input type='text' value='" + this.Name + "'/><br/>";
        //         webDialog.innerHTML += "link: <input type='text' value='" + this.Link + "'/><br/>";
        //         webDialog.innerHTML += "note: <input type='text' value='" + this.Note + "'/><br/>";
        //         webDialog.innerHTML += "<input type='button' value='Save'/><input type='button' value='Canceal'/>";

        //         web.DialogTag.cssText = "position : absolute; z-Index : 10; left : 0px; top : 0px; width : 100%; height : 100%;";

        //         document.body.appendChild(webDialogTag);
        //     } else {
        //         if (_.Link.match(/(http|https|ftp|mms|rtsp|gopher|socks4|socks5|thunder|flashget|qqdl):\/\/.*/)) {
        //             (new ForceWindow()).open(_.Link);
        //         } else if (_.Link.match(/[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-]*[\w@?^=%&amp;\/~+#-])?/)) {
        //             (new ForceWindow()).open('http://' + _.Link);
        //         } else {
        //             (new ForceWindow()).open(_.Link);
        //         }
        //     }
        //     _.Parent.handleLastOperateWeb(_); //显示或隐藏当前Web.
        // };
        // _.funForLMouseDblclick = function () {
        //     var t = new EditWeb(_);
        //     console.log(2)
        // };
        _.funForStartLMouseMoveWhileDown = function () { //开始移动。
            g.dragData = _;
            var e = lib.getEvent();
            _.isLMoveWhileDown = true;
            _.isFirstMousedownMove = true;
            g.initialOffsetX = _.initialOffsetX = e.clientX - _.RecLeft;
            g.initialOffsetY = _.initialOffsetY = e.clientY - _.RecTop;
            _.dragWeb = _.E.cloneNode(true);
            _.dragWeb.id = "drag" + _.ID;
            _.E.style.position = "absolute";
            _.E.parentNode.insertBefore(_.dragWeb, _.E);

            var maskLayer;
            if (U == $("maskeLayer")) {
                var maskLayer = $CE("div");
                maskLayer.id = "maskeLayer";
                lib.dom.setStyle(maskLayer, "position:absolute;z-Index:8;background-color:red;opacity:.50;moz-opacity:0.5;filter:alpha(opacity=30);");
                maskLayer.style.width = _.E.style.width;
                maskLayer.style.height = _.E.style.height;
                maskLayer.style.cursor = "move";
                _.E.appendChild(maskLayer);
            } else {
                maskLayer = $("maskeLayer");
            }

            try {
                maskLayer.setCapture();
            } catch (ex) {};
            //_.Ele才是被拖动的元素.
            g.elementDragClass = new ThreeDomEleClass(_.E, _.dragWeb, _.dragWeb); //????
            maskLayer.style.left = _.E.style.left = (e.clientX - _.initialOffsetX) + "px";
            maskLayer.style.top = _.E.style.top = (e.clientY - _.initialOffsetY) + "px";
            _.E.style.borderStyle = "dashed";
            _.E.style.borderWidth = "thin";
            _.E.style.cursor = "move";
            _.E.style.zIndex = 3;
        };

        _.funForLMouseMoveWhileDown = function () { //处于移动中。
            var e = lib.getEvent();
            _.E.style.left = (e.clientX - _.initialOffsetX) + "px";
            _.E.style.top = (e.clientY - _.initialOffsetY) + "px";
        };

        _.funForRMouseDown = function () {};
        _.funForRMouseUp = function () {};
        _.funForRMouseClick = function () {};
        _.funForRMouseDblclick = function () {};
        _.funForRMouseMoveWhileDown = function () {};
        _.funForMouseMoveWithoutDown = function () {};
        _.funForLMouseUpAfterMoveWhileDown = function () { //tmp:t,a,
            //<----state----
            g.dragData = undefined;
            _.isFirstMousedownMove = false; //恢复到初始标识状态。
            //----state---->
            _.E.position = "";
            var maskLayer = $("maskeLayer");
            if (maskLayer.parentNode) {
                maskLayer.parentNode.removeChild(maskLayer);
            }
            var index = -1;

            var t = $("drag" + _.ID); //拖动完毕，删除被复制的移动元素_.Ele.cloneNode(true);
            if (t != null) {
                lib.dom.setStyle(_.E, t.style.cssText); //将被拖动元素的css恢复到初始状态。
                t.parentNode.removeChild(t);
            }
            //start
            var e = lib.getEvent();
            if (u(g.elementDragClass)) { //在鼠标左键单击web时，此条件为真.
                return;
            }
            if (u(g.elementDragClass.drag)) { //在鼠标左键单击web时，此条件为真.
                return;
            }

            if (g.elementDragClass.drag.ele.parentNode != null) {
                g.elementDragClass.drag.ele.parentNode.removeChild(g.elementDragClass.drag.ele);
            }

            g.tableRowWeb = getDataByMouse(e); //放开鼠标时所在位置的table、row、web数据
            _.E.style.visibility = "";

            if (!u(g.tableRowWeb.tableData) && !u(g.tableRowWeb.tableData.selectWeb)) {
                g.tableRowWeb.tableData.selectWeb.n();
                if (!u(g.tableRowWeb.tableData.selectWebRow)) {
                    g.tableRowWeb.tableData.selectWebRow.delButton.style.visibility = "hidden";
                }
            }

            if (!u(g.tableRowWeb.rowData))
                g.tableRowWeb.tableData.selectWebRow = g.tableRowWeb.rowData; //鼠标移动后放开左键时所在的WebRow

            if (!u(g.tableRowWeb.tableData)) {
                if (!u(g.tableRowWeb.rowData)) {
                    if (g.elementDragClass.source.ele.parentNode != null) {
                        g.elementDragClass.source.ele.parentNode.removeChild(g.elementDragClass.source.ele);
                    }

                    if (!u(g.tableRowWeb.webData)) {
                        g.tableRowWeb.webData.isLMousedown = 0; //[0,*1]-tag: the left mouse is lost or up
                        g.selectedData.resume();
                        if (g.tableRowWeb.webData.ID != _.ID) { //如果插入其它元素位置上.
                            index = lib.data.getOrder(g.tableRowWeb.rowData.Webs, g.tableRowWeb.webData);
                            _.moveWebItem(g.tableRowWeb.rowData, index); //添加web
                        } else {
                            _.Parent.d();
                        }
                    } else { //when g.tableRowWeb.webData == undefined
                        var b = _.Parent; //don't remove
                        var index = g.tableRowWeb.rowData.Webs.length;
                        _.moveWebItem(g.tableRowWeb.rowData, index); //添加web
                    }
                    if (g.tableRowWeb.rowData.ID != _.Parent.ID) { //当前web所在的row改变了
                        _.n(); //原来位置所在row隐藏x
                        lib.dom.setStyle(_.Parent.delButton, "cursor:default;visibility:hidden;");
                    }
                    _.Parent = g.tableRowWeb.rowData;
                } else { // when (g.tableRowWeb.rowData == undefined)
                    //do nothing.
                }
            } else { //g.tableRowWeb.tableData == undefined

            }
            g.elementDragClass = U;
            //end
            _.Parent.handleLastOperateWeb(_); //显示或隐藏当前Web.
        };
        //----------<a> attribute--------------
        if (Sys.isMiniScreen || navigator.userAgent.match(/iPad/i)) //如果屏幕很小或者是ipad用户
        {
            // do nothing
        } else {

            EventForEle.call(_, {
                "E": _.E,
                "funForLMouseDown": _.funForLMouseDown,
                "funForLMouseUp": _.funForLMouseUp,
                // "funForLMouseClick": _.funForLMouseClick,
                // "funForLMouseDblclick": _.funForLMouseDblclick,
                "funForLMouseMoveWhileDown": _.funForLMouseMoveWhileDown,
                "funForRMouseDown": _.funForRMouseDown,
                "funForRMouseUp": _.funForRMouseUp,
                "funForRMouseClick": _.funForRMouseClick,
                "funForRMouseDblclick": _.funForRMouseDblclick,
                "funForRMouseMoveWhileDown": _.funForRMouseMoveWhileDown,
                "funForMouseMoveWithoutDown": _.funForMouseMoveWithoutDown,
                "funForLMouseUpAfterMoveWhileDown": _.funForLMouseUpAfterMoveWhileDown
            }); //inherit from the Class EventForWeb.
        }
        return _;
    };
}
//*-----------------------------------------------------

//+--------------------class WebRow---------------------
B.WebRow = function (p, q, parent, webIDHTML, numDisFirst) {
    var _ = this;
    Region.call(_); //inherit from the Class Region
    if (B.WebRowBase != U) {
        B.WebRowBase.call(this);
    }
    _.ID = p.toString();
    _.CateName = q;
    _.webIDHTML = webIDHTML;
    _.numDisFirst = numDisFirst;
    _.E = document.createDocumentFragment();
    _.dragEle = U;
    _.CateNameEle = U;
    _.addButton = $CE("A");
    _.delButton = $CE("A");
    _.delRowButton = $CE("A"); // delete a row.
    _.leftArrow = $CE("A");
    _.rightArrow = $CE("A");
    _.editAndAddEle = $CE("DIV");
    _.editCateNameEle = U; //edit the category's name.     
    _.lastOperateWeb = U;
    _.Parent = parent;
    _.initialOffsetX = 0;
    _.initialOffsetY = 0;
    _.isFirstMousedownMove = false;

    _.websIndex = [];
    _.Webs = [];
    _.dragTableDiv = {};
    _.lastDisWeb = {}; //在最后显示的web
    _.contentWidth = 998 - 12 - 12; // width - paddingLeft - paddingRight
    _.previousArrowsWidth = 50;
    _.nextArrowsWidth = 25;
    _.addButtonWidth = 11;
    _.deleteButtonWidth = 10;

    _.handleLastOperateWeb = function (_web) {
        if (u(_web.Parent.lastOperateWeb)) { //如果以前没有选定任何元素,则突出显示当前元素,打开"x"..
            _web.Parent.lastOperateWeb = _web;
            _web.m();
            lib.dom.setStyle(_web.Parent.delButton, "cursor:default;");
        } else if (_web.Parent.lastOperateWeb === _web) { //如果以前选定了当前元素,则不突出显示当前元素,关闭"x".
            _web.Parent.lastOperateWeb = U;
            _web.n();
            lib.dom.setStyle(_web.Parent.delButton, "cursor:default;visibility:hidden;");
        } else { //如果以前选定了本RowWeb中的其它元素,则不突出显示以前元素而是突出显示当前元素,打开"x".
            _web.Parent.lastOperateWeb.n();
            _web.Parent.lastOperateWeb = _web;
            _web.m();
            lib.dom.setStyle(_web.Parent.delButton, "cursor:default;");
        }
    };

    _.s = function (p) {
        if (u(p))
            return;
        if (__typeof__(p) === 'String') {
            p = eval('(' + p + ')');
        }
        //++-----create the mapping table--------------
        var tmpWebs;
        if (u(p.Mrowwebs)) { //如果没有子元素

        } else { //如果有子元素
            if (u(p.Mrowwebs.web.length)) { //如果只有一个元素
                tmpWebs = [];
                tmpWebs.push(p.Mrowwebs.web);
            } else { ////如果有多个个元素
                tmpWebs = p.Mrowwebs.web;
            }
            for (var i = 0; i < tmpWebs.length; i++) {
                var tmpA = new B.Web(tmpWebs[i].ID,
                    tmpWebs[i].Name,
                    tmpWebs[i].Link,
                    tmpWebs[i].Note,
                    tmpWebs[i].Cate,
                    tmpWebs[i].Cr,
                    tmpWebs[i].Key,
                    tmpWebs[i].Lans,
                    "A",
                    _);

                _.Webs.push(tmpA);
            }
        }
    };
    _.funForMouseOver = function () {
        if (0 < _.numDisFirst) { //if there is items hidening at the left .
            _.leftArrow.style.visibility = "";
        }

        var tmpIndex = lib.data.getOrder(_.Webs, _.lastDisWeb);
        if (tmpIndex < _.Webs.length - 1) { //if there is items hidening at the right.
            _.rightArrow.style.display = "";
        }
        _.addButton.style.display = "";
        _.delRowButton.style.display = "";
    };
    _.funForMouseOut = function () {
        _.leftArrow.style.visibility = "hidden";
        _.rightArrow.style.display = "none";
        _.addButton.style.display = "none";
        _.delRowButton.style.display = "none";
    };
    _.c = function () { //tmp:a,b,c,
        var a = $CE("td");
        a.id = _.ID.toString();;
        $SA(a, "relationalID", _.Parent.ID + "-" + _.ID);
        jQuery(a).addClass('web_page_table_row_middle');
        _.CateNameEle = $CE("A");
        _.CateNameEle.innerHTML = _.CateName;
        $SA(_.CateNameEle, "Link", g.domainDirectory + "/" + _.CateName);
        $SA(_.CateNameEle, "ParentID", _.ID);
        $SA(_.CateNameEle, "eleFlag", "CateNameEle");
        $SA(_.CateNameEle, "class", "web_page_table_row_middle_crh");
        //lib.dom.setStyle(_.CateNameEle, "margin-right:60px;color:#686868;cursor:default;font-size: 14px;"); 2020-3-27
        a.appendChild(_.CateNameEle);

        _.leftArrow.innerHTML = "<div class='leftArr' style='display:inline-block;height:0px;line-height:0px;;border:6px solid #000;border-color:transparent #629444 transparent transparent;'>&nbsp;&nbsp;</div>";
        $SA(_.leftArrow, "id", "lfArrow" + _.ID);
        $SA(_.leftArrow, "ParentID", _.ID);
        $SA(_.leftArrow, "title", "previous links");
        _.leftArrow.onclick = function () { // goPrevious; // addWeb is a function.
            // 当numDisFirst为0时，表示显示了第一个链接，把“左移”按钮置为失效
            if (_.numDisFirst === 0) {
                return;
            }
            var preWeb = _.getFWebFromPreRow(_.Webs[_.numDisFirst]);
            _.numDisFirst = lib.data.getOrder(_.Webs, preWeb);

            var t = "{'action':'numDisFirst','data':{'table':{'ID':'" + _.Parent.ID + "','row':{'ID':'" + _.ID + "','numDisFirst':'" + _.numDisFirst + "'}}}}";
            g.ComWithServer.add(g.URI.protocol + '://' + g.URI.authority + "/ResAddApp.aspx?paraStr=" + paraStr +"&flag=" + g.subdir, t);
            g.ComWithServer.startSend(); //将信息发往服务器.
            _.d();
            _.refresh(); //如果不记录位置数据，拖动将不正常.offset为0
        };
        lib.dom.setStyle(_.leftArrow, "cursor:default;visibility:hidden;");

        a.appendChild(_.leftArrow);
        var title = "";
        var b = lib.dom.getOffsetWidth(_.CateName) + _.previousArrowsWidth;

        var k = g.mainTableWidth / 1068;
        if (Sys.isMiniScreen) {
            k = g.mainTableWidth / 450;
        }

        for (var i = 0; i < _.Webs.length; i++) {

            if (i < _.numDisFirst) {} else {
                var c = _.Webs[i];
                if (u(c.Name)) continue;
                var webOffsetWidth = lib.dom.getOffsetWidth(c.Name) + 30;
                // 累计多个链接的宽度和
                if (b + webOffsetWidth + _.nextArrowsWidth + _.addButtonWidth + _.deleteButtonWidth < _.contentWidth || lib.browser.isMobile) { //显示10个link (2020手机浏览器全部显示)
                    if (u(c.Name)) alert("");
                    b = b + webOffsetWidth;
                   // console.log(c.Name + ': ' + b);
                    c.Parent = _;
                    a.appendChild(c.c().E);
                    _.lastDisWeb = c;
                }
            }
        }

        _.rightArrow.innerHTML = "&nbsp;&nbsp;<div style='display:inline-block;height:0px;line-height:0px;border:6px solid #000;border-color:transparent transparent transparent #629444;'></div>&nbsp;";
        $SA(_.rightArrow, "id", "rtArrow" + _.ID);
        $SA(_.rightArrow, "ParentID", _.ID);
        $SA(_.rightArrow, "title", "next links2");
        _.rightArrow.onclick = function () {

            var tmpIndex = lib.data.getOrder(_.Webs, _.lastDisWeb);
            if (tmpIndex < _.Webs.length - 1) {
                _.numDisFirst = tmpIndex + 1;
                var t = "{'action':'numDisFirst','data':{'table':{'ID':'" + _.Parent.ID + "','row':{'ID':'" + _.ID + "','numDisFirst':'" + _.numDisFirst + "'}}}}";
                g.ComWithServer.add(g.URI.protocol + '://' + g.URI.authority + "/ResAddApp.aspx?paraStr=" + paraStr+"&flag=" + g.subdir, t);
                g.ComWithServer.startSend(); //将信息发往服务器.

                _.d();
                _.refresh();
            } else {
                return;
            }

        }; //goNext; // addWeb is a function.

        lib.dom.setStyle(_.rightArrow, "cursor:default;display:none;");
        a.appendChild(_.rightArrow);

        // _.addButton.innerHTML = "<div id='add" + _.ID + "' ParentID='" + _.ID + "' relationalID='" + _.Parent.ID + "-" + _.ID + "' style=''>+</div>";
        _.addButton.innerHTML = "+"
        _.addButton.setAttribute('class', 'plus');
        _.addButton.setAttribute('id', 'id' + _.ID)
        _.addButton.setAttribute('ParentID', _.ID)
        _.addButton.setAttribute('relationalID', _.Parent.ID + "-" + _.ID)
        $SA(_.addButton, "title", "Add a link");
        _.addButton.onclick = addWeb; // addWeb is a function.
        lib.dom.setStyle(_.addButton, "color:#55A520;cursor:default;display:none;");
        //document.writeln("isMobile: " + lib.browser.isMobile);
        if (g.state.isOperable && lib.browser.isMobile) { //如果是当前用户的网页,并且是手机浏览器,则不显示.
            _.addButton.style.display = "";
        }
        a.appendChild(_.addButton);
        if (g.state.isOperable) { //如果用户登录则显示X.
            _.delButton.innerHTML = "x";
        }
        $SA(_.delButton, "id", "delete" + _.ID);
        $SA(_.delButton, "ParentID", _.ID);
        $SA(_.delButton, "title", "Delete a link");
        _.delButton.onclick = function () {
            _.h();
            lib.dom.setStyle(_.delButton, "cursor:default;display:none;");
        };
        lib.dom.setStyle(_.delButton, "cursor:default;display:none;");
        a.appendChild(_.delButton);

        lib.dom.clearChildren(_.E); //如果有子节点,清除子节点.如果不清除子节点可能会重复添加了节点.
        if (_.E.parentNode == U) {
            _.E = $CE("TR");
        }
        lib.dom.setStyle(_.E, "background-color:#fff;height:30px;");
        $SA(_.E, "relationalID", _.Parent.ID + "-" + _.ID);
        _.E.appendChild(a);

        if (g.state.isOperable) { //如果用户登录则显示X.

            _.delRowButton.onclick = deleteRow;
            $SA(_.delRowButton, "title", "Delete this row");
        }
        _.delRowButton.setAttribute('class', 'wsd')

        $SA(_.delRowButton, "id", "deleteRow" + _.ID);
        $SA(_.delRowButton, "relationalID", _.Parent.ID + "-" + _.ID);
        lib.dom.setStyle(_.delRowButton, "color:#55A520;cursor:default;margin-right:4px");
        _.delRowButton.style.display = "none";
        var tmp = $CE("td");
        lib.dom.setStyle(tmp, "border-top:solid 2px #FFF;border-bottom:solid 2px #FFF;");
        tmp.style.width = "10px";
        tmp.appendChild(_.delRowButton);
        _.E.appendChild(tmp);

        _.E.onmousedown = function (p) {
            var isLButton;
            if (navigator.userAgent.indexOf("MSIE") > 0)
                isLButton = (lib.getEvent().button == 1); //IE中左键标记为1
            else
                isLButton = (lib.getEvent().button == 0); //Firefox中左键标记为0
            if (isLButton) {
                eventHandler.fun_onmousedown(p);
            }
        };
        _.E.onmouseover = _.funForMouseOver;
        _.E.onmouseout = _.funForMouseOut;

        $SA(_.E, "id", _.ID);
        $SA(_.E, "ParentID", _.Parent.ID);

        _.funForLMouseDown = function () {};
        _.funForLMouseUp = function () {};
        _.funForLMouseClick = function () {
            open(_.CateNameEle.getAttribute("Link"));
        };

        _.funForLMouseDblclick = function () {
            if (U != _.editCateNameEle && U != _.editCateNameEle.parentNode) {
                _.editCateNameEle.parentNode.removeChild(_.editCateNameEle);
            }
            _.editCateNameEle = $CE("DIV");
            _.editCateNameEle.innerHTML = "<input id='cateNameInputID' style='border: 0;font-size: 14px;height: 100%;' type='text' value='" + _.CateName + "' size='" + lib.data.getStrLength(_.CateName) + "' onkeydown='closeCateNameEditor(this)'/><span style='    display: inline-block;background: #cdcbcb;height: 15px;width: 15px;color: #fff;border-radius: 50%;line-height: 14px;font-size: 12px;text-align: center;position: absolute;right: 0px;top: 50%;transform: translateY(-50%);' onclick='closeCateNameEditor(this)'>x</span>";
            $SA(_.editCateNameEle, "relationalID", _.Parent.ID + "-" + _.ID);
            $SA(_.editCateNameEle, "style", " height: 23px; line-height: 20px; padding-right: 15px;border: 1px solid #629444; border-left: 5px solid #629444; border-radius: 5px; padding-left: 5px;display:inline;background-color: #fff;borderStyle:solid;borderWidth:1px;borderColor:#5858FA;position:absolute;");
            addEleAround(_.CateNameEle, _.editCateNameEle, "same");
            $("cateNameInputID").focus();
            _.CateNameEle.style.visibility = "hidden";
        };
        _.funForStartLMouseMoveWhileDown = function () { //开始移动。
            //<----state----
            _.isFirstMousedownMove = true;
            //----state---->
            var e = lib.getEvent();

            _.initialOffsetX = e.x - _.RecLeft;
            _.initialOffsetY = e.y - _.RecTop;
            _.dragEle = $CE("DIV"); //create a DIV element to contain the table. It can be dragged.
            var dragTable = _.Parent.E.cloneNode(false);
            var hiddenEle = _.E.cloneNode(true);
            // hiddenEle.style.visibility = "hidden";
            _.E.parentNode.insertBefore(hiddenEle, _.E);
            dragTable.appendChild(_.E);
            _.dragEle.appendChild(dragTable);
            _.dragEle.style.position = "absolute";
            _.E.style.cursor = "move";
            document.body.appendChild(_.dragEle);
        };
        _.funForLMouseMoveWhileDown = function () { //当拖动某行的标题时，会运行。
            var e = lib.getEvent();
            _.dragEle.style.left = (e.x - _.initialOffsetX) + "px";
            _.dragEle.style.top = (e.y - _.initialOffsetY) + "px";
        };

        _.funForRMouseDown = function () {};
        _.funForRMouseUp = function () {};
        _.funForRMouseClick = function () {};
        _.funForRMouseDblclick = function () {};
        _.funForRMouseMoveWhileDown = function () {};
        _.funForMouseMoveWithoutDown = function () {};
        _.funForLMouseUpAfterMoveWhileDown = function () { //t,a,b,
            g.dragEle = U;
            g.initialOffsetX = 0;
            g.initialOffsetY = 0;
            var e = lib.formatEvent(lib.getEvent());
            _.isFirstMousedownMove = false; //恢复到初始标识状态。
            _.E.style.position = "";
            var stillData = getDataByMouse(e);
            var webRowE = stillData.rowData; //鼠标处的静止的webRow
            if (!u(webRowE)) {
                //exchange the two rows' position.
                var tmpCates = webRowE.Parent.Categories;

                var k = lib.data.getOrder(tmpCates, webRowE); //鼠标处的静止的WebRow的索引位置
                var i = lib.data.getOrder(_.Parent.Categories, _); //获取移动的_paraWebRow的索引位置
                var stillRowMiddleX = (_.RecLeft + _.RecRight) / 2; //获取移动的_paraWebRow的原处的坐标

                var t = 0; //偏移量.
                if ((findPos(_.dragEle).absoluteTop + _.dragEle.clientHeight / 2) > ((_.RecTop + _.RecBottom) / 2)) { //如果是想下移动
                    t++;
                } else {
                    //do nothing.
                }
                var a = k + t;
                _.moveRowItem(stillData.tableData, a);
            } else if (stillData.tableData != U && stillData.rowData == U) {
                _.moveRowItem(stillData.tableData, 0);
            } else {
                //do nothing.
            }
            _.Parent.d(); //未测试。
            _.dragEle.parentNode.removeChild(_.dragEle);
            _.E.onmousedown = eventHandler.fun_onmousedown;
        };

        EventForEle.call(_, {
            "E": _.CateNameEle,
            "funForLMouseDown": _.funForLMouseDown,
            "funForLMouseUp": _.funForLMouseUp,
            "funForLMouseClick": _.funForLMouseClick,
            "funForLMouseDblclick": _.funForLMouseDblclick,
            "funForLMouseMoveWhileDown": _.funForLMouseMoveWhileDown,
            "funForRMouseDown": _.funForRMouseDown,
            "funForRMouseUp": _.funForRMouseUp,
            "funForRMouseClick": _.funForRMouseClick,
            "funForRMouseDblclick": _.funForRMouseDblclick,
            "funForRMouseMoveWhileDown": _.funForRMouseMoveWhileDown,
            "funForMouseMoveWithoutDown": _.funForMouseMoveWithoutDown,
            "funForLMouseUpAfterMoveWhileDown": _.funForLMouseUpAfterMoveWhileDown
        }); //inherit from the Class EventForWeb.

        return _;
    };
}

//+--------------------------------------------------
B.WebTable = function (p, q, containerEle, Parent) {
    var _ = this;
    Region.call(_); //inherit from the Class Region
    if (B.WebTableBase != U) {
        B.WebTableBase.call(this);
    }
    _.ID = p.toString();
    _.Name = q;
    _.Parent = Parent;
    _.Categories = [];
    _.outerHTML = U;
    _.E = document.createDocumentFragment();
    _.Container = containerEle;
    _.titleEle = $CE("A");
    _.editTableTitleEle = U;
    _.delTableButton = $CE("A");
    _.headEle = U; //头元素
    _.TBodyEle = U;
    _.selectWeb = U;
    _.selectWebRow = U;
    _.lastOperateRow = U; //record the category which was operated.
    _.inicialOffsetX = {};
    _.inicialOffsetY = {};
    _.isFirstMousedownMove = false;


    d_queren_g = function () {
        _.f();
        var index = _.Parent.Tables.indexOf(_)
        _.Parent.deleteDataAndDom(index);
        _.Parent.refresh();


    }
    var d_del_i = 0;
    _.g = function () {
        document.getElementById("duihuakuang").style.display = "block";
       // localStorage.setItem('type_active', 1);
        d_del_i = lib.data.getOrder(_.Parent.Tables, _);
    };


    _.m = function () {
        if (!+"\v1") {
            return _.TBodyEle;
        } else {
            return _.E;
        }

    };

    _.c = function () { //tmp:t
        _.E = $CE("table");
        if (Sys.isMiniScreen) {
            lib.dom.setStyle(_.E, "width:100%;");
            // lib.dom.setStyle(_.E, "width:" + (g.mainTableWidth) + "px;");
        } else {
            lib.dom.setStyle(_.E, "width:100%;");
            // lib.dom.setStyle(_.E, "width:" + g.mainTableWidth + "px;");
        }
        _.E.className += "roundTable";
        if (!+"\v1") {
            this.TBodyEle = $CE("TBODY");
        }
        tmpTr = $CE("TR"); //头元素
        _.headEle = tmpTd = $CE("TD");
        $SA(_.headEle, "colspan", "2");
        tmpTr.appendChild(tmpTd);

        if (g.state.isOperable) { //如果用户登录则显示X.
            _.delTableButton.onclick = _.g;


        } else {
            _.delTableButton.onclick = function () {
                _.addTableToUser();
            };
        }
        _.delTableButton.setAttribute('class', 'wsd');
        $SA(_.delTableButton, "title", "Delete this table");
        $SA(_.delTableButton, "id", "deleteTable" + _.ID);
        $SA(_.delTableButton, "ParentID", _.ID);
        $SA(_.delTableButton, "relationalID", _.ID);
        jQuery(_.delTableButton).addClass('web_page_table_btn_deleteTable');
        _.titleEle.innerHTML = u(_.Name) ? "." : _.Name;
        _.titleEle.ondblclick = _.h;
        _.headEle.appendChild(_.titleEle);
        _.headEle.appendChild(_.delTableButton);
        _.headEle.style.backgroundColor = g.config.headBackgroundColor;
        _.headEle.className += "tableTitle";
        _.m().appendChild(tmpTr);

        for (var i = 0; i < _.Categories.length; i++) {
            _.Categories[i].Parent = _;
            _.m().appendChild(_.Categories[i].c().E);
        }
        tmpTr = $CE("TR");
        tmpTd = $CE("TD");
        jQuery(tmpTd).addClass('web_page_table_row_last');
        tmpTd.innerHTML = "<a title='Add a table' relationalID='" + _.ID + "' class='addTableButton' onclick='editAddTable(this);'>" + lan["addTable"] + "</a>" + "<a title='Add a category' relationalID='" + _.ID + "' style='cursor:default;float:right;background-color:#629444;width:15px; height:15px; line-height:14px;text-align:center; margin-top:3px;' onclick='g.editAddCategory(this);'>+</a>";
        $SA(tmpTd, "colspan", "2");
        tmpTr.appendChild(tmpTd);
        _.m().appendChild(tmpTr);

        if (!+"\v1") {
            _.E.appendChild(_.TBodyEle);
        }
        _.funForLMouseDown = function () {

        };
        _.funForLMouseUp = function () {

        };
        _.funForLMouseClick = function () {};

        _.funForLMouseDblclick = function () {};

        _.funForStartLMouseMoveWhileDown = function () {
            //<----state----
            _.isLMoveWhileDown = true
            _.isFirstMousedownMove = true;
            //----state---->
            g.dragData = _;
            e = lib.getEvent();
            _.inicialOffsetX = e.clientX - _.RecLeft;
            _.inicialOffsetY = e.clientY - _.RecTop;
            var t = _.E.cloneNode(true);
            var tmpNextEle = _.E.nextSibling;
            if (u(tmpNextEle)) {
                _.Container.appendChild(t);
            } else {
                _.Container.insertBefore(t, tmpNextEle);
            }
            t.id = "drag" + _.ID;
            // t.style.visibility = "hidden";
            _.E.style.position = "absolute";
            _.E.style.cursor = "move";
            _.E.style.margin = "0px"; //将margin值设为0，防止相对鼠标的偏移。
        };

        _.funForLMouseMoveWhileDown = function () {
            e = lib.getEvent();
            _.E.style.left = e.clientX - _.inicialOffsetX + "px";
            _.E.style.top = e.clientY - _.inicialOffsetY + "px";
        };
        _.funForRMouseDown = function () {};
        _.funForRMouseUp = function () {};
        _.funForRMouseClick = function () {};
        _.funForRMouseDblclick = function () {};
        _.funForRMouseMoveWhileDown = function () {};
        _.funForMouseMoveWithoutDown = function () {};
        _.funForLMouseUpAfterMoveWhileDown = function () {
            //<----state----
            _.isLMoveWhileDown = false;
            //----state---->
            g.dragData = undefined;
            var a = (findPos(_.E).absoluteTop + _.E.clientHeight / 2); //放在此，先保存位置
            e = lib.getEvent();
            g.tableRowWeb = getDataByMouse(e);
            var t = $("drag" + _.ID);
            t.parentNode.removeChild(t);
            _.E.style.cursor = "default";
            _.E.style.position = "";
            _.E.style.margin = "10px 0px 10px 0px"; //将margin值恢复原状。 index.css .roundTable margin:10px 0px 10px 0px; 

            if (!u(g.tableRowWeb.tableData)) {
                if (g.tableRowWeb.tableData.ID != _.ID) {
                    var k = lib.data.getOrder(g.tableRowWeb.tableData.Parent.Tables, g.tableRowWeb.tableData);
                    var i = lib.data.getOrder(_.Parent.Tables, _);
                    var tmpAdd = 0; //偏移量.

                    var b = ((_.RecTop + _.RecBottom) / 2);
                    if (a > b) { //如果是想下移动
                        tmpAdd++;
                    } else {
                        //do nothing.
                    }
                    var tmpIndex = k + tmpAdd;
                    _.moveTableItem(_.Parent, tmpIndex);
                }
            }
        };

        EventForEle.call(_, {
            "E": _.headEle,
            "funForLMouseDown": _.funForLMouseDown,
            "funForLMouseUp": _.funForLMouseUp,
            "funForLMouseClick": _.funForLMouseClick,
            "funForLMouseDblclick": _.funForLMouseDblclick,
            "funForLMouseMoveWhileDown": _.funForLMouseMoveWhileDown,
            "funForRMouseDown": _.funForRMouseDown,
            "funForRMouseUp": _.funForRMouseUp,
            "funForRMouseClick": _.funForRMouseClick,
            "funForRMouseDblclick": _.funForRMouseDblclick,
            "funForRMouseMoveWhileDown": _.funForRMouseMoveWhileDown,
            "funForMouseMoveWithoutDown": _.funForMouseMoveWithoutDown,
            "funForLMouseUpAfterMoveWhileDown": _.funForLMouseUpAfterMoveWhileDown
        }); //inherit from the Class EventForWeb.

        return _;
    };


    _.h = function () {
        _.editTableTitleEle = $CE("DIV");
        //_.editTableTitleEle.onmousemove = function () { var e = lib.getEvent(); e = EventUtil.formatEvent(e); if (e.stopPropagation) e.stopPropagation(); else e.cancelBubble = true; return false; };
        _.editTableTitleEle.innerHTML = "<input id='tableNameInputID' style='outline:none;border: none;max-width: 900px' type='text' value='" + (_.Name || ".") + "' size='" + (u(_.Name) ? 5 : lib.data.getStrLength(_.Name)) + "' onkeydown='closeTableTitleEditor(this)'/><span style='cursor:default;width: 14px;height: 14px;background-image: url(\"image/3.png\");background-repeat: no-repeat;border-radius: 50%;background-color: #dcdcdc;background-position: center;background-size: 130% 130%;display: inline-block;margin-right: 3px' onclick='closeTableTitleEditor(this)'></span>";
        $SA(_.editTableTitleEle, "ParentID", _.ID);
        $SA(_.editTableTitleEle, "style", "display:flex;padding:2px;background-color:#fff;border-radius:5px;borderStyle:solid;borderWidth:1px;borderColor:#5858FA;position:absolute;border: 1px solid #629444;text-indent:10px;");
        addEleAround(_.titleEle, _.editTableTitleEle, "same");
        $("tableNameInputID").focus();
        _.titleEle.style.visibility = "hidden";
    };

    _.s = function (p) { //tmp:t,
        if (u(p))
            return;
        if (__typeof__(p) === 'String') {
            p = eval('(' + p + ')');
        }
        if (u(p.Mrows)) {
            return;
        }
        var t = p.Mrows.row;
        if (u(t.length)) {
            t = [];
            t.push(p.Mrows.row);
        }
        for (var i = 0; i < t.length; i++) {
            var tmpA = new B.WebRow(t[i].Id, t[i].Ct, _, "", t[i].NumDisFirst);
            _.Categories.push(tmpA);
            tmpA.s(t[i]);
        }
    };
}
//*--------------------------------------------------

B.Page = function () {
    var _ = this;
    Region.call(_); //inherit from the Class Region
    if (B.PageBase != U) {
        B.PageBase.call(this);
    }
    _.Model = {};
    _.Model.Tables = []; //working...
    _.E = _.Container = $("tdA");

    _.addTable = function () {

    };

    _.l = function () { //tmp:t,
        var t = new B.Page();
        for (var i = 0; i < _.Tables.length; i++) {
            t.Tables.push(_.Tables[i].l());
        }
        return t;
    };

    _.bindData = function (p) { //tmp:t,a, import Data to the table
        if (u(p))
            return;
        if (__typeof__(p) === 'String') {
            p = eval('(' + p + ')');
        }
        _.ID = p.page.Id;
        var t = p.page.Mtables.table;
        if (u(t.length)) {
            t = [];
            t.push(p.page.Mtables.table);
        }
        _.Tables = []; //将Tables数据清空.
        for (var i = 0; i < t.length; i++) {
            var a = new B.WebTable(t[i].Id, t[i].Name, $("tdA"), _);
            _.Tables.push(a);
            a.s(t[i]);
        }
    };

    _.createDom = function () {

        _.E.innerHTML = ""; //清空子元素
        if (_.Tables == null) {
            return;
        }
        for (var i = 0; i < _.Tables.length; i++) {
            _.E.appendChild(_.Tables[i].c().E);
        }
        return _;
    };

    _.d = function () { //tmp:t,
        var t = _.Container;
        if (U != t) {
            while (t.childNodes.length >= 1) {
                t.removeChild(t.firstChild);
            }
            for (var i = 0; i < _.Tables.length; i++) {
                var ele = _.Tables[i].c().E;
                _.Container.appendChild(ele);
            }
            return _;
        }
    };

    _.deleteDataAndDom = function(index) {
        // 先删除节点
        _.deleteDom(index);
        _.deleteData(index);
    }

    _.deleteData = function(index) {
        _.Tables.splice(index, 1);
    }

    _.deleteDom = function(index) {
        _.Container.removeChild(_.Tables[index].E);
    }

    _.$ = function (p) {
        for (var i = 0; i < _.Tables.length; i++) {
            if (p == _.Tables[i].ID) {
                return _.Tables[i];
            }
        }
    };
}
//+---------------------------------------------------
function getWebFromTablesByID(id, webTables) {
    for (var k in webTables) {
        if (__typeof__(k) == "WebTable") {
            for (var i = 0; i < webTables[k].Categories.length; i++) {
                var tmpCate = webTables[k].Categories[i];
                for (var j = 0; j < tmpCate.Webs.length; j++) {
                    if (tmpCate.Webs[j].ID == id) {
                        return tmpCate.Webs[j];
                    }
                }
            }
        }
    }
}
//*---------------------------------------------------
//+---------------------------------------------------
function getWebByIDWithPre(id, _webTable) {
    var preString = "webElement2010";
    id = id.substring(preString.length, id.length);
    return getWebByID(id, _webTable);
}
//*---------------------------------------------------

//+---------------------------------------------------
function getWebByMose(e) {
    for (var k in g.WebTable) {
        for (var i = 0; i < g.WebTable[k].Categories.length; i++) {
            for (var j = 0, tmpCate = g.WebTable["First"].Categories[i]; j < tmpCate.Webs.length; j++) {
                var tmpWeb = tmpCate.Webs[j];
                if (tmpWeb.ID == g.elementDragClass.source.ele.getAttribute("ID") && tmpWeb.isOver(e.pageX, e.pageY)) { //edit
                    return tmpWeb;
                }
            }
        }
    }
}
//*---------------------------------------------------
//+---------------------------------------------------
function getDataByMouse(e) //获得鼠标移动后，鼠标所在位置的web元素,不包括被拖动的web元素.
{
    var tableData = U;
    var rowData = U;
    var webData = U;
    var isFirst = U;
    if (!g.page) {
        return;
    }
    var tmpTables = g.page.Tables;

    for (var i in tmpTables) {
        if (tmpTables[i].isOverEvent && tmpTables[i].isOverEvent(e)) {
            tableData = tmpTables[i];
            for (var j = 0; j < tableData.Categories.length; j++) {
                if (tableData.Categories[j].isOverEvent(e)) {
                    rowData = tableData.Categories[j];
                    for (var k = 0; k < rowData.Webs.length; k++) {
                        if (rowData.Webs[k].isOverEvent(e)) {
                            webData = rowData.Webs[k];
                            break;
                        }
                    }
                    if (rowData.Webs.length > 0 && e.clientX < rowData.Webs[0].RecLeft) {
                        isFirst = true;
                    }
                    break;
                }
            }
            break;
        }
    }

    return {
        "tableData": tableData,
        "rowData": rowData,
        "webData": webData,
        "isFirst": isFirst
    };
}
//*---------------------------------------------------

function addTable(value) { //tmp:t,a,
    if (lib.getEvent().keyCode == 13 || value.type != "text") {
        var con = $("addTableID");
        var t = con.getElementsByTagName("INPUT")[0];
        if (validateInput(t, /^\s*$/g) == false) {
            return;
        }
        var relationalID = con.getAttribute("relationalID");
        var tableName = t.value;
        var a = new B.WebTable((new Date).getTime() + "TB", tableName, $("tdA"), g.page);
        var index = lib.data.getOrder(g.page.Tables, g.page.$(relationalID)) + 1;
        a.Parent.Tables.splice(index, 0, a);
        a.a(index);
        a.Parent.d();
        // a.Parent.r();
        close(con);
        g.tip.display("正在处理数据...");
    }
}
//*---------------------------------------------------

//+---------------------------------------------------
function addEleAround(oldEle, newEle, orientation) //orientation: topleft, topright, righttop, rightbottom, bottomright, bottomleft, leftbottom, lefttop, same.
{
    document.body.appendChild(newEle);

    var newLeft = newEle.offsetLeft;
    var newTop = newEle.offsetTop;

    var pos = findPos(oldEle);

    switch (orientation) {
        case "topleft":
            newEle.style.left = pos.absoluteLeft + "px";
            newEle.style.top = (pos.absoluteTop - newEle.offsetHeight) + "px";
            break;

        case "topright":
            newEle.style.left = (pos.absoluteLeft + oldEle.offsetWidth - newEle.offsetWidth) + "px";
            newEle.style.top = (pos.absoluteTop - newEle.offsetHeight) + "px";
            break;

        case "righttop":
            newEle.style.left = (pos.absoluteTop + oldEle.offsetWidth) + "px";
            newEle.style.top = pos.absoluteTop + "px";
            break;

        case "rightbottom":
            newEle.style.left = (pos.absoluteLeft - newEle.offsetWidth) + "px";
            newEle.style.top = (pos.absoluteTop + oldEle.offsetHeight - newEle.offsetHeight) + "px";
            break;

        case "bottomright":
            newEle.style.left = (pos.absoluteLeft + oldEle.offsetWidth - newEle.offsetWidth) + "px";
            newEle.style.top = (pos.absoluteTop + oldEle.offsetHeight) + "px";
            break;

        case "bottomleft":
            newEle.style.left = pos.absoluteLeft + "px";
            newEle.style.top = (pos.absoluteTop + oldEle.offsetHeight) + "px";
            break;

        case "leftbottom":
            newEle.style.left = (pos.absoluteLeft - newEle.offsetWidth) + "px";
            newEle.style.top = (pos.absoluteTop + oldEle.offsetHeight - newEle.offsetHeight) + "px";
            break;

        case "lefttop":
            newEle.style.left = (pos.absoluteLeft - newEle.offsetWidth) + "px";
            newEle.style.top = pos.absoluteTop + "px";
            break;

        case "same":
            newEle.style.left = pos.absoluteLeft + "px";
            newEle.style.top = pos.absoluteTop + "px";
            break;
    }

    return newEle;
}
//*---------------------------------------------------
//+----------------set attribute----------------------
function $SA() {
    var tmp = arguments[0];
    if (typeof tmpTagname === 'string') {
        return $(tmp).setAttribute(arguments[1], arguments[2]);
    } else {
        return tmp.setAttribute(arguments[1], arguments[2]);
    }
}
//*---------------------------------------------------

//+----------------create element---------------------
function $CE() {
    var tmpTagname = arguments[0];
    if (typeof tmpTagname === 'string') {
        return document.createElement(tmpTagname);
    }
}
//*---------------------------------------------------

//function webClose(value) {
//    closeWindow(value.parentNode);
//}
function webClose(value) {
    // 2020 ~
    if (lib.browser.isMobile && value.parentNode && value.parentNode.parentNode) {
        closeWindow(value.parentNode.parentNode);
    } else {
        closeWindow(value.parentNode);
    }
}


function showDeleteWeb(value) {
    var tmp = value.getAttribute("ID");
    g.volatileArray["showDeleteWeb"] = new settimeoutData(4000, tmp)
    setTimeout(delayShowDeleteWeb, 2000);
}

function delayShowDeleteWeb() {
    if (!g.volatileArray["showDeleteWeb"])
        return;
    var tmpWeb = getWebByIDWithPre(g.volatileArray["showDeleteWeb"].argument);
    delete g.volatileArray["showDeleteWeb"];
    tmpWeb.k(tmpWeb);
}

function deleteWeb() //tmp:t,a,b,
{
    var a = lib.formatEvent().target.getAttribute("relationalID").split("-");
    var t = g.page.$(a[0]).$(a[1]);
    lib.dom.setStyle(t.delButton, "cursor:default;visibility:hidden;");
    for (var i = 0; i < t.Webs.length; i++) {
        if (t.Webs[i].ID == t.Parent.selectWeb.ID) {
            t.Webs.splice(i, 1);
            t.d();
            t.r();
            t.lastOperateWeb = t.Parent.selectWeb;
            break;
        }
    }
}

function EditWeb(p) //argument:tableRowWebData
{
    var _ = this;
    Region.call(_); //inherit from the Class Region

    _.E = $CE("DIV");
    _.E.className = "div_editor_modify";

    if (typeof p == 'undefined') return;

    var a = g.mouseEvent;

    _.ID = "editor" + p.ID;

    $SA(_.E, "id", _.ID);
    $SA(_.E, "NameSourceValue", p.Name);
    $SA(_.E, "LinkSourceValue", p.Link);
    $SA(_.E, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);

    var tmpEle = $CE("INPUT");

    tmpEle.type = "text";
    tmpEle.value = p.Name;
    tmpEle.size = p.Name.length + 1;
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    jQuery(tmpEle).addClass('input_editor_modify');
    tmpEle.onkeydown = editorSaveAndClose;
    var tmpText = document.createTextNode(lan["title"]);
    jQuery(tmpText).wrap('<div class="label"></div>')
    _.E.appendChild(tmpText);
    _.E.appendChild(tmpEle);

    tmpEle = $CE("INPUT");
    tmpEle.type = "text";
    tmpEle.value = p.Link;
    tmpEle.size = p.Link.length || 5;
    tmpEle.onkeydown = editorSaveAndClose;
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    jQuery(tmpEle).addClass('input_editor_modify');
    var tmpText = document.createTextNode(lan["link"]);
    jQuery(tmpText).wrap('<div class="label"></div>')
    _.E.appendChild(tmpText);
    _.E.appendChild(tmpEle);

    tmpEle = $CE("INPUT");
    tmpEle.value = p.Note;
    if (p.Note == null) {
        tmpEle.size = 10;
    } else {
        tmpEle.size = p.Note.length + 2;
    }
    tmpEle.onkeydown = editorSaveAndClose;
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    jQuery(tmpEle).addClass('input_editor_modify');
    var tmpText = document.createTextNode(lan["note"]);
    jQuery(tmpText).wrap('<div class="label"></div>')
    _.E.appendChild(tmpText);
    _.E.appendChild(tmpEle);

    tmpEle = $CE("INPUT");
    $SA(tmpEle, "type", "button");
    $SA(tmpEle, "class", "btn");
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    tmpEle.onclick = editorSaveAndClose;
    tmpEle.value = lan["save"];
    _.E.appendChild(tmpEle);

    tmpEle = $CE("INPUT");
    $SA(tmpEle, "type", "button");
    $SA(tmpEle, "class", "btn");
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    tmpEle.onclick = editorCancel;
    tmpEle.value = lan["reset"];
    _.E.appendChild(tmpEle);

    tmpEle = $CE("INPUT");
    $SA(tmpEle, "type", "button");
    $SA(tmpEle, "class", "btn");
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    tmpEle.onclick = deleteWebTwo;
    tmpEle.value = lan["delete"];
    _.E.appendChild(tmpEle);

    tmpEle = $CE("SPAN");
    $SA(tmpEle, "style", "padding: 5px;position: absolute;right: 10px;top: 0px;font-size: 22px;");
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    tmpEle.onclick = editorSaveAndClose;
    tmpEle.innerHTML = "x";
    _.E.appendChild(tmpEle);

    _.E = p.Parent.Parent.Parent.E.appendChild(_.E);
    p.EditEle = _.E; //
    _.setRecByEle();

    var width = _.RecRight - _.RecLeft;
    var height = _.RecBottom - _.RecTop;
    if (p.RecLeft + width > document.body.scrollLeft + document.body.offsetWidth) {
        if (p.RecRight - width < document.body.scrollLeft) {
            _.E.style.left = document.body.scrollLeft + "px";
        } else {
            _.E.style.left = (p.RecRight - width) + "px";
        }
    } else {
        _.E.style.left = p.RecLeft + "px";
    }
    _.E.style.top = (p.RecTop - height) + "px";
}

function closeCateNameEditor(p) //After editting the category's name, close the div and submit the data.
{
    var tmpNameObj = p.parentNode.getElementsByTagName("INPUT")[0];
    p.size = lib.data.getStrLength(tmpNameObj.value);
    if (lib.getEvent().keyCode == 13 || p.type != "text") {

        if (validateInput(tmpNameObj, /^\s*$/g, "Error") == false) {
            return;
        }
        var tmpIDArray = p.parentNode.getAttribute("relationalID").split("-");
        var tmpTable = g.page.$(tmpIDArray[0]);
        var a = tmpTable.$(tmpIDArray[1]);
        a.CateName = tmpNameObj.value;
        a.CateNameEle.innerHTML = a.CateName;
        a.CateNameEle.style.visibility = "";
        p.parentNode.parentNode.removeChild(p.parentNode);
        a.Parent.lastOperateRow = a;
        a.u();
        a.refresh();
    }
}


//+---------------add a table to the page--------------
function editAddTable(value) { //WebTable(ID,Name,containerEle,Parent)   tmp:t,
    var t = $CE("DIV");
    t.id = "addTableID";
    $SA(t, "relationalID", value.getAttribute("relationalID"));
    t.style.position = "absolute";
    t.style.backgroundColor = "#fff";
    t.style.borderStyle = "solid";
    t.style.borderWidth = "1px";
    t.style.borderColor = "#629444";
    t.style.width = "285px";
    t.innerHTML = "<table style='width:100%;'>" +
        "<tr><td><span class='wsd' style='position: absolute;top: 9px;right: 13px;font-size: 14px;' onclick='closeWindow(this.parentNode.parentNode.parentNode);'></span></td></tr>" +
        "<tr class='label'><td>" + lan["25"] + "</td></tr>" +
        "<tr><td class='inputWrapper'><input type='text' onfocus='resumeStyle(this)' onkeydown='addTable(this)'/></td>" +
        "<td class='btnWrapper'><input type='button' class='btn' value='" + lan["save"] + "' onclick='addTable(this)'/></tr>" +
        "<tr class='label'><td>" + lan["28"] + "</td></tr>" +
        "<tr><td class='inputWrapper'><input id='websiteID' type='text'/></td>" +
        "<td class='btnWrapper'><input type='button' class='btn' onclick='g.craw(0)' value='" + lan["26"] + "'/></td>" +
        "<tr class='label'><td>" + lan["27"] + "</td></tr>" +
        "<tr><td><textarea id='webdataID'></textarea></td>" +
        "<td class='btnWrapper'><input type='button' class='btn' onclick='g.craw(1)' value='" + lan["26"] + "'/></td>"
    addEleAround(value, t, "same");
}

function closeTableTitleEditor(p) //tmp:t,
{
    if (lib.getEvent().keyCode == 13 || p.type != "text") {
        var t = g.page.$(p.parentNode.getAttribute("ParentID"));
        t.Name = p.parentNode.getElementsByTagName("INPUT")[0].value;
        t.titleEle.innerHTML = t.Name;
        t.titleEle.style.visibility = "";
        p.parentNode.parentNode.removeChild(p.parentNode);
        t.u();
        t.r();
    }
}

x_queren_g = function () {



    for (var i = 0; i < x_q_tmpCate.length; i++) {
        if (x_q_tmpCate[i].ID == x_q_a.ID) {
            x_q_tmpCate.splice(i, 1);
            x_q_a.Parent.d();
            x_q_a.Parent.refresh();
            x_q_a.Parent.lastOperateRow = x_q_a;
            break;
        }
    }
    x_q_a.f();

}


var x_q_tmpCate;
var x_q_a;

function deleteRow() //tmp:t,     如果移动到weblazy.js中会出现错误("没有定义").
{
    //localStorage.setItem("type_active", 2);
    document.getElementById("duihuakuang").style.display = "block";
    var t = lib.formatEvent(arguments[0]).target.getAttribute("relationalID").split("-");
    var tmpTable = g.page.$(t[0]);
    x_q_a = tmpTable.$(t[1]);
    x_q_tmpCate = x_q_a.Parent.Categories;
}

function editorSaveAndClose() //value is this    如果移动到weblazy.js中会出现错误("没有定义").
{
    var e = lib.formatEvent(arguments[0]);
    if (e.keyCode == 13 || e.target.type != "text") {
        var relationalIDs = e.target.getAttribute("relationalID").split("-");
        var tableID = relationalIDs[0];
        var rowID = relationalIDs[1];
        var webID = relationalIDs[2];
        var table = lib.data.getObByAttribute(g.page.Tables, "ID", tableID);
        var row = lib.data.getObByAttribute(table.Categories, "ID", rowID);
        var tmpWeb = row.$(webID);
        var tmpEle = $("editor" + webID); // an instance's ID is "editor3"
        var tmpObjs = tmpEle.getElementsByTagName("INPUT");
        if (validateInput(tmpObjs[0], /^\s*$/g, "Error") == false) {
            return;
        }
        tmpWeb.Name = tmpObjs[0].value;
        tmpWeb.Link = tmpObjs[1].value;
        tmpWeb.Note = tmpObjs[2].value;
        tmpWeb.i();
        tmpWeb.h(tmpWeb);
        tmpEle.parentNode.removeChild(tmpEle);
        tmpWeb.EditEle = U;
    }
}

function editorCancel(value) {
    var t = $("editor" + lib.formatEvent(arguments[0]).target.getAttribute("relationalID").split("-")[2]);
    t.getElementsByTagName("INPUT")[0].value = t.getAttribute("NameSourceValue");
    t.getElementsByTagName("INPUT")[1].value = t.getAttribute("LinkSourceValue");
}

function deleteWebTwo() {
    var t = lib.formatEvent(arguments[0]).target.getAttribute("relationalID").split("-");
    var tmpTable = g.page.$(t[0]);
    var tmpRow = tmpTable.$(t[1]);
    var tmpWeb = tmpRow.$(t[2]);
    // 向服务发送删除数据
    tmpWeb.g();
    if (!tmpWeb.EditEle.parentNode) {
        debugger;
    }
    tmpWeb.EditEle.parentNode.removeChild(tmpWeb.EditEle);
    tmpWeb.EditEle = U;
};

function editorDelete(value) { //delete the "Web".
    //send data to the server.
    var tmpParentID = value.getAttribute("ParentID"); //get the id of the parent dom of the editor.
    var tmpEle = $(tmpParentID); // an instance's ID is "editor3"
    var tmpWebID = tmpParentID.substring(6, tmpParentID.length); // remove the string "editor"
    var tmpID = "webElement2010" + tmpWebID;
    var tmpWeb = getWebByIDWithPre(tmpID);
    var tmpRow = tmpWeb.Parent;
    lib.dom.setStyle(tmpRow.delButton, "cursor:default;visibility:hidden;");
    for (var i = 0; i < tmpRow.Webs.length; i++) {
        if (tmpRow.Webs[i].ID == tmpWebID) {
            tmpRow.Webs.splice(i, 1);
            tmpRow.d();
            tmpRow.r();
            tmpRow.lastOperateWeb = tmpWeb;
            break;
        }
    }
    tmpEle.parentNode.removeChild(tmpEle); //delete the editor.
    tmpWeb.EditEle = U;
}

//+---------------global function-------------------------
function findPos(obj) {
    if (u(obj))
        return;
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            if (obj.style.position == "absolution") {
                break;
            }
            obj = obj.offsetParent;
        }
    } else if (obj.x && obj.y) {
        cureft += obj.x;
        curtop += obj.y;
    }
    return {
        "absoluteLeft": curleft,
        "absoluteTop": curtop
    };
}
//*-------------------------------------------------------

/**
 * 定义ForceWindow类构造函数
 * 无参数
 * 无返回值
 */
function ForceWindow() {
    this.r = document.documentElement;
    this.f = $CE("FORM");
    this.f.target = "_blank";
    this.f.method = "post";
    this.r.insertBefore(this.f, this.r.childNodes[0]);
}

/**
 * 定义open方法
 * 参数sUrl：字符串，要打开窗口的URL。
 * 无返回值
 */
ForceWindow.prototype.open = function (sUrl) {
    this.f.action = sUrl;
    this.f.submit();
}

/**
 * 实例化一个ForceWindow对象并做为window对象的一个子对象以方便调用
 * 定义后可以这样来使用：window.force.open("URL");
 */
window.force = new ForceWindow();



Object.prototype.Serialize = function () {
    var type = __typeof__(this);
    switch (type) {
        case 'Array': {
            var strArray = '[';
            for (var i = 0; i < this.length; ++i) {
                var value = '';
                if (this[i]) {
                    value = this[i].Serialize();
                }
                strArray += value + ',';
            }
            if (strArray.charAt(strArray.length - 1) == ',') {
                strArray = strArray.substr(0, strArray.length - 1);
            }
            strArray += ']';
            return strArray;
        }
        case 'Date': {
            return 'new Date(' + this.getTime() + ')';
        }
        case 'Boolean':
        case 'Function':
        case 'Number':
            return this.toString();
        case 'String': {
            return '"' + this.toString() + '"';
        }
        default: {
            var serialize = '{';
            for (var key in this) {
                if (key == 'Serialize') continue;
                var subserialize = 'null';
                if (!u(this[key])) {
                    subserialize = this[key].Serialize();
                }
                serialize += '\r\n' + key + ' : ' + subserialize + ',';
            }
            if (serialize.charAt(serialize.length - 1) == ',') {
                serialize = serialize.substr(0, serialize.length - 1);
            }
            serialize += '\r\n}';
            return serialize;
        }
    }
};

function __typeof__(p) //p:p
{
    if (p && p.constructor) {
        var a = p.constructor.toString();
        return a.substr(0, a.indexOf('(')).replace('function', '').replace(/(^\s*)|(\s*$)/ig, '');
    }
    return typeof (p);
}


function close(value) {
    if (value == null || u(value) || u(value.parentNode)) return;
    value.parentNode.removeChild(value);
}

function closeWindow(value) {
    if (u(value.parentNode)) {
        return;
    }
    value.parentNode.removeChild(value);
    jQuery('#addTableID').remove()
}

function validateInput(obj, reg, msg) {
    if (obj.value == "" || reg.test(obj.value)) {
        obj.style.color = "Red";
        obj.value = (u(msg)) ? lan["29"] : msg;
        return false;
    }

    return true;
}

function resumeStyle(obj, uselessMSG) {
    obj.style.color = "#000000";
}

function addWeb() {
    var trigger = lib.formatEvent(arguments[0]).target;
    var tmpIDs = trigger.getAttribute("relationalID").split("-");
    var webRow = g.page.$(tmpIDs[0]).$(tmpIDs[1]);
    if (webRow.editAndAddEle.parentNode == null || webRow.editAndAddEle.parentNode.parentNode == null) {
        webRow.n();
    } else {
        closeWindow(webRow.editAndAddEle);
    }
}

function addWebAndClose(p) //add the web to WebRow after editting the data.   working 99
{
    var evt = lib.getEvent();
    var pageX=evt.pageX;
    var pageY=evt.pageY;
    if (evt.keyCode == 13 || p.type != "text") {
        if (false == g.user.isLogined()) {
            var tmp = g.disLoginAndRegister();
            return;
        }
        var relationalIDs = p.getAttribute("relationalID").split("-");
        var t = $("editAndAddEleID" + relationalIDs[1]);
        var webRow = lib.data.getObByAttribute(g.page.Tables, "ID", relationalIDs[0]).$(relationalIDs[1]);
        var tmpInputEles = t.getElementsByTagName("INPUT");
        if (validateInput(tmpInputEles[0], /^\s*$/g) == false) {
            tmpInputEles[0].value = lan["31"];
        }
        var scrollTop=document.documentElement.scrollTop;
        var tmpName = tmpInputEles[0].value.length > 60 ? tmpInputEles[0].value.substr(0, 57) + "..." : tmpInputEles[0].value;
        webRow.o(new B.Web((new Date).getTime() + "Web", tmpName, tmpInputEles[1].value, tmpInputEles[2].value, webRow.CateName, "48778", tmpInputEles[2].value, ["cn", "en"], "A"), webRow.Webs.length); //(ID, Name,Link, Note, Cate, Cr, Key,Lans,tagName)
        document.documentElement.scrollTop=scrollTop
        closeWindow(t);
    }
};

function addCategory(value) {
    var tmpEve = lib.getEvent();
    if (tmpEve.keyCode == 13 || value.type != "text") {
        var tmpNameObj = value.parentNode.getElementsByTagName("INPUT")[0];
        if (validateInput(tmpNameObj, /^\s*$/g) == false) {
            return;
        }
        var cateName = tmpNameObj.value;
        var newRow = new B.WebRow((new Date).getTime() + "CATE", cateName, g.page.$(value.parentNode.getAttribute("relationalID")), "");
        newRow.Parent.Categories.push(newRow);
        newRow.Parent.Parent.d();
        newRow.Parent.Parent.refresh();
        close(value.parentNode);
        newRow.Parent.lastOperateRow = newRow;
        newRow.a(newRow.Parent.Categories.length);
    }
}

function LightOn(ele) {
    lib.transparentDiv.on(); //把div添加到body
    var contentDiv = $CE("div"); //创建内容div
    //计算顶部位置值
    var winH;
    if (window.innerHeight) { // all except IE
        winH = window.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        // IE 6 Strict Mode
        winH = document.documentElement.clientHeight;
    } else if (document.body) { // other
        winH = document.body.clientHeight;
    }
    var top = parseInt(parseInt(winH * 0.25) + (document.body.scrollTop || document.documentElement.scrollTop));
    contentDiv.style.width = "368px"; //宽度
    // contentDiv.style.height = "423px";
    contentDiv.style.background = "url(image/login_bg.png) 0 0/100% 100% no-repeat;"
    contentDiv.id = "contentDiv"; //设置id
    //计算左边位置
    var left = Math.ceil(((document.body.scrollWidth) - parseInt(contentDiv.style.width.replace('px', ''))) / 2) + document.body.scrollLeft;
    contentDiv.style.top = top + "px"; //设置顶部边距
    contentDiv.style.left = left + "px"; //设置左边距
    jQuery(contentDiv).addClass('dialog_sign');
    contentDiv.innerHTML = lib.loginModule(); //把内容窗体添加到contentDiv
    document.body.appendChild(contentDiv); //把div添加到body
    if ($("UsernameID").value == "")
        $("UsernameID").focus();
    else
        $("PasswordID").focus();
    //所有的Select控件设为不可见
    var arr = document.getElementsByTagName("select");
    var i = 0;
    while (i < arr.length) {
        arr[i].style.visibility = "hidden";
        i++;
    }
    //清除关机效果
    this.cancle = function () {
        if (!u($("transparentDiv"))) {
            document.body.removeChild($("transparentDiv"));
        }
        var tmp = $("contentDiv");
        tmp.parentNode.removeChild(tmp);
        var arr = document.getElementsByTagName("select");
        var i = 0;
        //把所有的select控件设为可见
        while (i < arr.length) {
            arr[i].style.visibility = "visible";
            i++;
        }
    }
}

function stringDom(dom) {
    var o = document.createElement("div");
    o.appendChild(dom);
    return o.innerHTML
}

function EditWeb(p) //argument:tableRowWebData
{
    var _ = this;
    Region.call(_); //inherit from the Class Region

    _.E = $CE("DIV");
    _.E.className = "div_editor_modify";

    if (typeof p == 'undefined') return;

    var a = g.mouseEvent;

    _.ID = "editor" + p.ID;

    $SA(_.E, "id", _.ID);
    $SA(_.E, "NameSourceValue", p.Name);
    $SA(_.E, "LinkSourceValue", p.Link);
    $SA(_.E, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);

    var tmpEle = $CE("INPUT");

    tmpEle.type = "text";
    tmpEle.value = p.Name;
    tmpEle.size = p.Name.length + 1;
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    jQuery(tmpEle).addClass('input_editor_modify');
    tmpEle.onkeydown = editorSaveAndClose;
    var tmpText = document.createTextNode(lan["title"]);
    tmpText = '<div class="label">' + stringDom(tmpText) + '</div>'
    jQuery(_.E).append(tmpText);
    _.E.appendChild(tmpEle);

    tmpEle = $CE("INPUT");
    tmpEle.type = "text";
    tmpEle.value = p.Link;
    tmpEle.size = p.Link.length || 5;
    tmpEle.onkeydown = editorSaveAndClose;
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    jQuery(tmpEle).addClass('input_editor_modify');
    var tmpText = document.createTextNode(lan["link"]);
    tmpText = '<div class="label">' + stringDom(tmpText) + '</div>'
    jQuery(_.E).append(tmpText);
    _.E.appendChild(tmpEle);

    tmpEle = $CE("INPUT");
    tmpEle.value = p.Note;
    if (p.Note == null) {
        tmpEle.size = 10;
    } else {
        tmpEle.size = p.Note.length + 2;
    }
    tmpEle.onkeydown = editorSaveAndClose;
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    jQuery(tmpEle).addClass('input_editor_modify');
    var tmpText = document.createTextNode(lan["note"]);
    tmpText = '<div class="label">' + stringDom(tmpText) + '</div>'
    jQuery(_.E).append(tmpText);
    _.E.appendChild(tmpEle);

    var tempWrap = $CE("div");
    $SA(tempWrap, "class", "btnWrap");
    tmpEle = $CE("INPUT");
    $SA(tmpEle, "type", "button");
    $SA(tmpEle, "class", "btn");
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    tmpEle.onclick = editorSaveAndClose;
    tmpEle.value = lan["save"];
    tempWrap.appendChild(tmpEle)
    // _.E.appendChild(tmpEle);

    tmpEle = $CE("INPUT");
    $SA(tmpEle, "type", "button");
    $SA(tmpEle, "class", "btn");
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    tmpEle.onclick = editorCancel;
    tmpEle.value = lan["reset"];
    tempWrap.appendChild(tmpEle)
    // _.E.appendChild(tmpEle);

    tmpEle = $CE("INPUT");
    $SA(tmpEle, "type", "button");
    $SA(tmpEle, "class", "btn");
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    tmpEle.onclick = deleteWebTwo;
    tmpEle.value = lan["delete"];
    tempWrap.appendChild(tmpEle)
    jQuery(_.E).append(tempWrap);

    tmpEle = $CE("SPAN");
    $SA(tmpEle, "style", "position: absolute;top: 10px;right: 13px;");
    $SA(tmpEle, "relationalID", p.Parent.Parent.ID + "-" + p.Parent.ID + "-" + p.ID);
    tmpEle.onclick = editorSaveAndClose;
    tmpEle.setAttribute('class', 'wsd');
    _.E.appendChild(tmpEle);

    _.E = p.Parent.Parent.Parent.E.appendChild(_.E);
    if (!_.E) {
        debugger;
    }
    p.EditEle = _.E; //
    _.setRecByEle();

    var width = _.RecRight - _.RecLeft;
    var height = _.RecBottom - _.RecTop;
    if (p.RecLeft + width > document.body.scrollLeft + document.body.offsetWidth) {
        if (p.RecRight - width < document.body.scrollLeft) {
            _.E.style.left = document.body.scrollLeft + "px";
        } else {
            _.E.style.left = (p.RecRight - width) + "px";
        }
    } else {
        _.E.style.left = p.RecLeft + "px";
    }
    _.E.style.top = (p.RecTop - height) + "px";
}

// 登录弹框
function LightOn(ele) {
    lib.transparentDiv.on(); //把div添加到body
    var contentDiv = $CE("div"); //创建内容div
    //计算顶部位置值
    var winH;
    if (window.innerHeight) { // all except IE
        winH = window.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        // IE 6 Strict Mode
        winH = document.documentElement.clientHeight;
    } else if (document.body) { // other
        winH = document.body.clientHeight;
    }
    var top = parseInt(parseInt(winH * 0.25) + (document.body.scrollTop || document.documentElement.scrollTop));
    contentDiv.id = "contentDiv"; //设置id
    contentDiv.style.width = "368px"; //宽度
    // contentDiv.style.height = "423px";
    contentDiv.style.background = "url('image/login_bg.png') 0 0/cover no-repeat"
    //计算左边位置
    // var left = Math.ceil(((document.body.scrollWidth) - parseInt(contentDiv.style.width.replace('px', ''))) / 2) + document.body.scrollLeft;
    contentDiv.style.top = top + "px"; //设置顶部边距
    contentDiv.style.left = "50%"; //设置左边距
    contentDiv.style.transform = 'translateX(-50%)';
    jQuery(contentDiv).addClass('dialog_sign');
    contentDiv.innerHTML = lib.loginModule(); //把内容窗体添加到contentDiv
    document.body.appendChild(contentDiv); //把div添加到bodyn  
    if ($("UsernameID").value == "")
        $("UsernameID").focus();
    else
        $("PasswordID").focus();
    //所有的Select控件设为不可见
    var arr = document.getElementsByTagName("select");
    var i = 0;
    while (i < arr.length) {
        arr[i].style.visibility = "hidden";
        i++;
    }
    //清除关机效果
    this.cancle = function () {
        if (!u($("transparentDiv"))) {
            document.body.removeChild($("transparentDiv"));
        }
        var tmp = $("contentDiv");
        tmp.parentNode.removeChild(tmp);
        var arr = document.getElementsByTagName("select");
        var i = 0;
        //把所有的select控件设为可见
        while (i < arr.length) {
            arr[i].style.visibility = "visible";
            i++;
        }
    }
}

function lightboxSetBlack(ele) {
    var scrW;
    var scrH;
    if (window.innerHeight && window.scrollMaxY) {
        // Mozilla
        scrW = window.innerWidth + window.scrollMaxX;
        scrH = window.innerHeight + window.scrollMaxY;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        // IE 6 Strict Mode
        scrW = document.documentElement.clientWidth;
        scrH = document.documentElement.clientHeight;
    } else if (document.body) {
        // IE Mac 
        scrW = document.body.clientWidth;
        scrH = document.body.clientHeight;
    }
    ele.style.display = "block";
    ele.style.width = scrW;
    ele.style.height = scrH;
}


//------------------------- sign on ------ sign in--------------------

function hideTab(ele) {
    ele.style.display = 'none';
}

function minimize(ele) {
    ele.style.width = 0;
    ele.style.height = 0;
}

function signOnOrSignIn(index) {
    var signonTab = $("signonTab");
    var signinTab = $("signinTab");
    if (index == 1) {
        signinTab.style.display = "";
        signonTab.style.display = "none";
    } else {
        signinTab.style.display = "none";
        signonTab.style.display = "";
    }
}

function showTab(tabHeadId, tabContentId) {
    var tabDiv = document.getElementById("light");
    var taContents = tabDiv.childNodes;
    for (var i = 0; i < taContents.length; i++) {
        if (taContents[i].id != null && taContents[i].id != 'tabsHead') {
            taContents[i].style.display = 'none';
        }
    }
    var contentDiv = document.getElementById('contentDiv')
    if (tabContentId == 'tabContent1') {
        contentDiv.style.background = "url('image/login_bg.png') 0 0/100% 100% no-repeat"
    } else if (tabContentId == 'tabContent2') {
        contentDiv.style.background = "url('image/register_bg.png') 0 0/100% 100% no-repeat"
    }
    document.getElementById(tabContentId).style.display = 'block';
    var ele_tabsHead = document.getElementById('tabsHead');
    var tabHeads = ele_tabsHead.getElementsByTagName('a');
    for (var i = 0; i < tabHeads.length; i++) {
        tabHeads[i].className = 'tabs';
    }
    jQuery('#' + tabHeadId).addClass('curtab').siblings().removeClass('curtab')
    // document.getElementById(tabHeadId).className = 'curtab';
    document.getElementById(tabHeadId).blur();
}

// ----------------------- begin router ---------------------------------------
var paraStr='';
function f_check_IP(ip) {
    var re = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;//正则表达式   
    if (re.test(ip)) {
        if (RegExp.$1 < 256 && RegExp.$2 < 256 && RegExp.$3 < 256 && RegExp.$4 < 256)
            return true;
    }
    return false;
    //return true;
}
function Router(){
    this.routes={};
    this.currentURL='';
}
 
Router.prototype.route = function(path,callback){
    this.routes[path] = callback || function(){};
}
 
Router.prototype.refresh = function () {
    var requestUrl = "";
    if (f_check_IP(location.hostname)) {
        requestUrl = location.hash.slice(1);
        var indexOfStr = requestUrl.lastIndexOf("/");
        paraStr = requestUrl.substring(0, indexOfStr);
    }
    else {
        requestUrl = location.hash.slice(1) || '/main';
    }
    //var indexOfStr = requestUrl.lastIndexOf("/");
    //paraStr = requestUrl.substring(0, indexOfStr);
    //this.currentURL = requestUrl.substring(indexOfStr);
    this.currentURL = requestUrl;
    this.routes[this.currentURL](paraStr);
}
 
Router.prototype.init = function () {
    window.addEventListener('load',this.refresh.bind(this),false);
    window.addEventListener('hashchange',this.refresh.bind(this),false);
}
 
window.Router = new Router();
if (f_check_IP(location.hostname)) {
    requestUrl = location.hash.slice(1);
    var indexOfStr = requestUrl.lastIndexOf("/");
    paraStr = requestUrl.substring(0, indexOfStr);
    Router.route(paraStr+'/main', function (paraStr) {
        g.getMainData(paraStr);
    })
    Router.route(paraStr +'/private', function (paraStr) {
        g.getPrivateData(paraStr);
    })

    Router.route(paraStr + '/public', function (paraStr) {
        g.getPublicData(paraStr);
    });
    var h = $('hostID');
    if (h != undefined) {
        h.href ="#"+paraStr + '/main';
    }
    var p = $('publicID');
    if (p != undefined) {
        p.href = "#" +paraStr + '/public';
    }
    lib.cookie.set("username", paraStr, 30, "/", true);



}
else {
    Router.route('/main', function (paraStr) {
        g.getMainData(paraStr);
    })

    Router.route('/private', function (paraStr) {
        g.getPrivateData(paraStr);
    })

    Router.route('/public', function (paraStr) {
        g.getPublicData(paraStr);
    })

    var h = $('hostID');
    if (h != undefined) {
        h.href ='#/main';
    }
    var p = $('publicID');
    if (p != undefined) {
        p.href ='#/public';
    }

}

window.Router.init();

// --------------------------- end router ------------------------------

//测试运行
function testFunc() {
    g.fun();
}

function lazyLoad() {
    tmpUrl = g.domainDirectory + "/weblazy.js";
    sendAndGetData(true, tmpUrl, function (_resData) {
        eval(_resData);
    });
}